Hello, I'm new here and I need help with inserting values into a database using mysqli. I have been searching for a few days and have found nothing I can use. I receive no errors, but it still doesn't insert into the database. <? include 'connect.php'; $Date = date('jS F Y'); $sql2 = "INSERT into userinfo (firstname, lastname, email, joined) VALUES ('$_POST[Firstname]','$_POST[Lastname]','$_POST[email]','$Date')"; $result = mysqli_query($conn, $sql2); $select = mysqli_query($conn,"select userinfoID from userinfo where firstname = '$_POST[Firstname]' and lastname = '$_POST[Lastname]' and email = '$_POST[email]' and joined = '$Date'"); if($fetch = mysqli_fetch_array($select)){ $sql = "INSERT into login (username, password, userinfoID) VALUES ('$_POST[Username]','$_POST[Password]',$fetch[userinfoID])"; $result = mysqli_query($conn, $sql); } echo $sql; echo $sql2; if(!$conn){ die('Error: ' . mysqli_error($conn)); } ?> PHP:
One suggestion ,, Try Debugging your script.. 1. Echo Your SQL Statements 2. Try executing your Obtained SQL Statements Then you will see the exact error
Tried that, no errors, everything seems fine. It says it inserted the values in, but in the database, nothing shows up. Thanks though.
<? include 'connect.php'; $Date = date('jS F Y'); $sql2 = "INSERT INTO userinfo (firstname, lastname, email, joined) VALUES ($_POST['Firstname'],$_POST['Lastname'],$_POST['email'],$Date)"; $result = mysqli_query($conn, $sql2); $select = mysqli_query($conn,"SELECT * FROM userinfo WHERE firstname = $_POST['Firstname'] and lastname = $_POST['Lastname'] and email = $_POST['email'] and joined = $Date"); if($fetch = mysqli_fetch_array($select)){ $sql = "INSERT INTO login (username, password, userinfoID) VALUES ($_POST['Username'],$_POST['Password'],$fetch['userinfoID'])"; $result = mysqli_query($conn, $sql); } echo $sql; echo $sql2; if(!$conn){ die('Error: ' . mysqli_error($conn)); } ?> PHP: No idea if this will help, its just written slightly different. You could also write your $conn function into the connect.php file, that would help clean up your code.