I have a very simple HTML form, which uses POST to send the data to the PHP script. It gives no errors, just doesn't insert the data into the database. I have checked that the actual data is in the variables, and cannot see any problems with the code.
The script is below:

<?php
	$user = $_POST['user']; // get vars from form
	$pass = $_POST['pass'];
	$fname = $_POST['fname'];
	$mname = $_POST['mname'];
	$lname = $_POST['lname'];
	$fullname = $_POST['fname'] . " " . $_POST['mname'] . " " . $_POST['lname'];
	$title = $_POST['title'];
	$gender = $_POST['gender'];
	$email = $_POST['email'];
	$site = $_POST['site'];
	$dob = $_POST['dob'];

$upass = md5($pass);

// connect and select db
$cxn = mysqli_connect("localhost","user1","pass","userdb") or die("cannot connect");

//debug testing data is captured correctly - yes
echo $user . $upass . $fullname . $title . $gender . $email . $site . $dob;

$data = "INSERT INTO users (uname, pass, email, site, fname, mname, lname, fullname, gender, title, dob) VALUES ('$user', '$upass', $email, '$site', '$fname', '$mname', '$lname', '$fullname', '$gender', '$title', '$dob')";

$insert = mysqli_query($cxn,$data);
?>

    Try the following to see if you get any error:

    $insert = mysqli_query($cxn,$data) or die("Query failed ($data): " . mysqli_error($cxn));
    

      It gives the following:
      Query failed (INSERT INTO users (uname, pass, email, site, fname, mname, lname, fullname, gender, title, dob) VALUES ('iyatos', '1a1dc91c907325c69271ddf0c944bc72', me@place.com, 'www.example.com', 'Joe', 'Test', 'Bloggs', 'Joe Test Bloggs', 'male', 'Mr', '2007-12-11')): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@place.com, 'www.example.com', 'Joe', 'Test', 'Bloggs', 'Joe Test Bloggs', 'male' at line 1

      It seems to have problems the the '@' symbol in the email, but I dont know how to fix that.

        Put single quotes around '$email' in your query.

          iyatos wrote:

          stupid mistake ... thank you

          No worries. I do stuff like that all the time... 😉

            Write a Reply...