I'm having some problem to include a connection file to my php page.
I have this connessione.php which receive from login.php the user and password to connect to my db:
<?php
$host="localhost";
$user=$_POST["username"];
$password= $_POST["password"];
$database = "Park";
$lingua=$_POST["lingua"];
$myconn= new mysqli($host,$user,$password,$database);
if($myconn->connect_error){
Header('Location: login.html');
}else{
Header('Location: form.html');
}
?>
This is my form.php that should use the connection.
<?php
require ('connessione.php');
$query="SELECT CodicePin from Pin";
$res=$myconn->query($query);
$row=$res->fetch_array(MYSQLI_NUM);
print_r($row);
?>
The problem is that it is unable to use $myconn established in connessione.php and when I try to login with right user/psw i'll be redirect to login.php.
However if i try to modify connessione.php like this and it execute the query without problem.
<?php
$host="localhost";
$user=$_POST["username"];
$password= $_POST["password"];
$database = "Park";
$lingua=$_POST["lingua"];
$myconn= new mysqli($host,$user,$password,$database);
if($myconn->connect_error){
Header('Location: login.html');
}else{
$query="SELECT CodicePin from Pin";
$res=$myconn->query($query);
$row=$res->fetch_array(MYSQLI_NUM);
print_r($row);
}
?>
How i can use the same connection established by connessione.php in other php page? Thanks, and sorry about my english :)