Prepared Statement Insert Problem
| From: | Jason Carson | Date: | Tue, 21 Jul 2009 10:01:39 +0000 |
| Subject: | Prepared Statement Insert Problem | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-46339@lists.php.net to get a copy of this message | ||
Hello everyone, I have a problem.
I use the following to *try* and insert data into my MySQL database...
//Variables come from a form
$username= $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
//Connect to the database
$connect = mysqli_connect("$hostname", "$dbusername", "$dbpassword",
"$database")or die("cannot connect");
//Find out how many rows in the database
$aidcount = mysqli_query ($connect, "SELECT * FROM administrator");
$numrows = mysqli_num_rows($aidcount);
//The next 3 lines are using prepared statements to insert data but the
//second line ...mysqli_stmt_bind_param.. results in this error...
//Fatal error: Only variables can be passed by reference in file.php line 46
$submitadmin = mysqli_prepare($connect2, "INSERT INTO administrator VALUES
(?, ?, ?, ?)");
mysqli_stmt_bind_param($submitadmin, "isss", '$numrows', '$admin',
sha1('$password'), '$email');
mysqli_stmt_execute($submitadmin);
...anyone know how I can solve this problem so I can insert data into my
database with prepared statements?