This question already has an answer here:
I am trying to declare two variables ($name & $users) depending on whether or not the input from the form of the html page is empty or not.
In these if conditions I am also try to call a function which would then insert the variables' data into MySQL database.
However, on page load I'm returned couple errors to the screen seen here. I am wondering where I am going wrong as I am pretty new to coding. Thank you.
The code below is what I use to execute this...
<?php
include_once('dbconnect.php')
if(!empty($name)){
$name = $_POST['test'];
$SELECT = "SELECT user_id FROM `users` WHERE username = '$name'";
$query = mysqli_query($con, $SELECT);
$users = mysqli_fetch_assoc($query);
callinsert();
} else {
$name = "NULL";
$users['user_id'] = "NULL";
callinsert();
}
function callinsert(){
$SELECT_ = "INSERT INTO `test` (id,name,user_id) VALUES (NULL, $name, '$users[user_id]')";
mysqli_query($con,$SELECT_);
return true;
}
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="session.php" method = "POST">
First Name: <input type="text" id="test" name="test">
<input type="submit" value="submit">
</form>
</body>
</html>
Aucun commentaire:
Enregistrer un commentaire