i'm new to php and coding in general. For a school project where i'm creating a website, i need to create a login page who's making the link with my batabase in mysql. So, i make a function connect to my database and i made an other function for inssert data on my sql. But, it dosen't work when i make it this why. But when i call my function connect on my function inssert, it doesn't work. Why ? I want to understand. Thank you by advanced.
This is my code :
function connect_db($host,$port,$dbname,$username,$passwd) {
try {
$bdd = new PDO('mysql:host=localhost;port=3306;dbname=my_shop', 'newuser', '0504');
//$dbh = null;
}
catch (PDOException $e) {
print "Erreur !: " . $e->getMessage() . "<br/>";
die();
}
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
connect_db ($host,$port,$dbname,$username,$passwd)
$username = $_POST['username'];
$password = $_POST['password1'];
$email = $_POST['email'];
$request= $bdd->prepare('INSERT INTO users (username,password,email) VALUES("'.$username.'","'.$password.'","'.$email.'")');
$request->execute();
print_r($request);
}