feedammo feedammo - 4 months ago 13
MySQL Question

PHP Signup form, Passing multi line MySql query

I was trying to understand how signup forms work, came across this. Got stuck at passing Sql queries through


<?php include 'connectdb.php';
if (isset($_POST['password'])) {

if (isset($_POST['email'])) {
if (isset($_POST['firstname'])) {
if (isset($_POST['lastname'])) {
$dob = $_POST['birthday_year']."-".$_POST['birthday_month']."- ".$_POST['birthday_day'];
$sex = "F"; /*Temporarliy passing!*/
$sqlCombined = "INSERT INTO `login` (username, password) VALUES (?,?); INSERT INTO `userdata` (username,dob,firstname,lastname,email,sex) VALUES (?,?,?,?,?,?)";
$stmt = $db-> prepare($sqlCombined);
$stmt -> bind_param('ssssssss', $username,$password,$username,$dob,$firstname,$lastname,$email,$sex);
$stmt -> execute();
$stmt -> close(); header("location: login.php"); ?>

Error Log:

Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in C:\xampp\htdocs\puddleweb\signup.php:67 Stack trace: #0 {main} thrown in C:\xampp\htdocs\puddleweb\signup.php on line 67


There is an issue with the query statement. See here. the prepare() function returns a boolean result. true if the statement succeeds and false if there is an error in the query. After the semicolon in a SQL statement, the query is finished, you cannot combine the statements like this. You need to break up these SQL queries. like this:

$stmtUser = prepare("INSERT INTO userdata (username,dob,firstname,lastname,email,sex) VALUES (?,?,?,?,?,?)");

$stmtLogin = prepare("INSERT INTO login (username, password) VALUES (?,?)");

Similar to this.

You will also have to create two bind_param statements using the two statement variables that we built ($stmtUser and $stmtLogin)

Hope this helps.

This Post may help you troubleshoot as well.