Re: Prepared Statement Insert Problem
| From: | Jason Carson | Date: | Tue, 21 Jul 2009 10:17:11 +0000 |
| Subject: | Re: Prepared Statement Insert Problem | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-46341@lists.php.net to get a copy of this message | ||
That worked, thanks!
> Remove the quotes around the variables in all your statements.
> For example, this statement:
> mysqli_stmt_bind_param($submitadmin, "isss", '$numrows',
> '$admin',
> sha1('$password'), '$email');
>
> could be rewritten as:
> mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin,
> sha1($password), $email);
>
> On Tue, Jul 21, 2009 at 8:01 PM, Jason Carson <jason@jasoncarson.ca>
> wrote:
>
>> 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?
>>
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>