Prepared Statement Insert Problem

Prepared Statement Insert Problem

am 21.07.2009 12:01:39 von Jason Carson

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

Re: Prepared Statement Insert Problem

am 21.07.2009 12:10:56 von Kesavan Rengarajan

--0016e6470cc46f3403046f347889
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

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 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
>
>

--0016e6470cc46f3403046f347889--

Re: Prepared Statement Insert Problem

am 21.07.2009 12:17:11 von Jason Carson

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
> 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
>>
>>
>



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Prepared Statement Insert Problem

am 21.07.2009 19:46:33 von Christopher Jones

kesavan trichy rengarajan wrote:

> could be rewritten as:
> mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin,
> sha1($password), $email);

Turning on E_STRICT in PHP 5.3 will show

PHP Strict Standards: Only variables should be passed by reference

This is also true in earlier versions although the warning isn't
displayed.

For compliance, try:

$s = sha1($password);
mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin, $s, $email);

Chris

--
Blog: http://blogs.oracle.com/opal
Twitter: http://twitter.com/ghrd

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Prepared Statement Insert Problem

am 22.07.2009 01:58:35 von Jason Carson

Done. Thanks for letting me know about that.


> kesavan trichy rengarajan wrote:
>
> > could be rewritten as:
> > mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin,
> > sha1($password), $email);
>
> Turning on E_STRICT in PHP 5.3 will show
>
> PHP Strict Standards: Only variables should be passed by reference
>
> This is also true in earlier versions although the warning isn't
> displayed.
>
> For compliance, try:
>
> $s = sha1($password);
> mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin, $s,
> $email);
>
> Chris
>
> --
> Blog: http://blogs.oracle.com/opal
> Twitter: http://twitter.com/ghrd
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Prepared Statement Insert Problem

am 22.07.2009 05:40:49 von Bilal Ahmad

--00163649a8b71d9551046f432316
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

Hi i wanna ask a question. I am trying to create an image on fly, please do
help me , following is the code.

*File Name : Font.php
Code: *



Image Creation



















Text
Text





*File Name : image.php
Code:*

[php]

$name = $_GET['text'];

$pic = imagecreatetruecolor(100, 100);
$text_color = imagecolorallocate($pic, 255, 255, 255);
imagestring($pic, 10, 15, 15, $name, $text_color);
$pi = Imagejpeg($pic,"pic.jpg");
echo $pi;
ImageDestroy($pic);

[/php]

*Problem: *

What this code is doing is that, it creates a new image with the text (that
user enters) on it, but loads the image that was created previously, I want
that it should display the text on the picture which users enter on the fly.
( e.g. If user enter TEXT as text it should display TEXT on the picture
displayed).Hope you got the problem.

Thanks

For me, it shoould work like this: User enters text intext filed (in
font.html) , when pressed button, image.php should create an im
On Tue, Jul 21, 2009 at 10:46 PM, Christopher Jones <
christopher.jones@oracle.com> wrote:

>
>
> kesavan trichy rengarajan wrote:
>
> > could be rewritten as:
> > mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin,
> > sha1($password), $email);
>
> Turning on E_STRICT in PHP 5.3 will show
>
> PHP Strict Standards: Only variables should be passed by reference
>
> This is also true in earlier versions although the warning isn't
> displayed.
>
> For compliance, try:
>
> $s = sha1($password);
> mysqli_stmt_bind_param($submitadmin, "isss", $numrows, $admin, $s,
> $email);
>
> Chris
>
> --
> Blog: http://blogs.oracle.com/opal
> Twitter: http://twitter.com/ghrd
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--00163649a8b71d9551046f432316--