I get an error when i try to execute this PS:

$ADJUST         = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
$ADJUST_PREP    = mysqli_stmt_prepare($connection, $ADJUST);
$ADJUST_PREP    = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

$pos_op = $_GET['pos'];
$pos_op = $pos_op + 1;

mysqli_stmt_execute($ADJUST_PREP) or die(mysqli_stmt_error($ADJUST_PREP));
mysqli_stmt_free_result($ADJUST_PREP);
mysqli_stmt_close($ADJUST_PREP);

The error: Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in C:\wamp\www\elvir\backend\ajaxPHP\moduler\galleri_img_pos.php on line 17

Line 17 is: mysqli_stmt_execute($ADJUST_PREP) or die(mysqli_stmt_error($ADJUST_PREP));

Member Avatar for LastMitch

@klemme

whats wrong with this prepared statement?

This wrong:

$ADJUST_PREP = mysqli_stmt_prepare($connection, $ADJUST);
$ADJUST_PREP = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);
$pos_op = $_GET['pos'];
$pos_op = $pos_op + 1;

Why are you using $ADJUST_PREP & $pos_op twice but different variable?

You only used it one time! The reason the error come up because mysqli_stmt_execute statment is confused of which statement to used because it's using both at the same time:

$ADJUST_PREP = mysqli_stmt_prepare($connection, $ADJUST); 

-and

$ADJUST_PREP = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

So another words your mysqli_connect probably didn't work.

I assume that $connection is your mysqli_connect

You need to rename one of those $ADJUST_PREP & $pos_op to a different name so it won't get confused.

$ADJUST             = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
$ADJUST_PREP        = mysqli_stmt_prepare($connection, $ADJUST);
$ADJUST_STMT_PREP   = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

$pos = $_GET['pos'];
$pos_op = $pos + 1;

mysqli_stmt_execute($ADJUST_STMT_PREP);
mysqli_stmt_free_result($ADJUST_STMT_PREP);
mysqli_stmt_close($ADJUST_STMT_PREP);

If I set to to fixed values, it updates just fine, but with the variables the error comes back again?

Starting to see double after a long day here, bur I hope to fix it before stopping for the day..

Shouldnt the above work?

Member Avatar for LastMitch

@klemme

 $ADJUST = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
 $ADJUST_PREP = mysqli_stmt_prepare($connection, $ADJUST);
 $ADJUST_STMT_PREP = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

 $pos = $_GET['pos'];
 $pos_op = $pos + 1;

 mysqli_stmt_execute($ADJUST_STMT_PREP);
 mysqli_stmt_free_result($ADJUST_STMT_PREP);
 mysqli_stmt_close($ADJUST_STMT_PREP);

If I set to to fixed values, it updates just fine, but with the variables the error comes back again?

Yes it looks right now have you test it out Yet?

Starting to see double after a long day here, bur I hope to fix it before stopping for the day..

I get it and I understand. It should work now. You did this very quickly. You won't get this error anymore:

mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean

Warning: mysqli_stmt_prepare() expects parameter 1 to be mysqli_stmt, object given in C:\wamp\www\elvir\backend\ajaxPHP\moduler\galleri_img_pos.php on line 11

Line 11 = $ADJUST_PREP = mysqli_stmt_prepare($connection, $ADJUST);

Hmm, the $connection should be fine though..

It shouldnt be this hard, but somehow it is..

Member Avatar for LastMitch

@klemme

Hmm, the $connection should be fine though..

It shouldnt be this hard, but somehow it is..

I agree with you.

Can you post your query for your connection.

Do you have this @ in front of your mysqli connection?

Try to put these `` quotes on your query

$host   = 'localhost';
$user   = 'root';
$pass   = '';
$db     = 'elvir';
$connection = mysqli_connect("$host", "$user", "$pass", "$db");
mysqli_set_charset($connection, 'utf8');

Any ideas? I use this connection variable throughout the CMS, and never ran into any issues?

I get the same error when quoted..

I tried clearing the cache, just to see if t somehow had saved the queries from before, but to no luck either.

Thanks for looking at it!!

It works, when i do thhis:

$adjust         = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = 2";
$ADJUST_PREP    = mysqli_prepare($connection, $adjust) or die(mysqli_error($connection));

$pos = $_GET['pos'];
$pos_op = $pos + 1;

mysqli_stmt_execute($ADJUST_PREP)or die(mysqli_stmt_error($connection));
mysqli_stmt_free_result($ADJUST_PREP)or die(mysqli_error($connection));
mysqli_stmt_close($ADJUST_PREP)or die(mysqli_error($connection));

So leaving out the mysqli_stmt_bind_param, and setting the value in the query to a fixed nnumber, makes it work. That is just not what i need...

Any idea why mysqli_stmt_bind_param is creating this error?

Member Avatar for LastMitch

@klemme

Any idea why mysqli_stmt_bind_param is creating this error?

For the "i", change to this 'i'

From this

$ADJUST_STMT_PREP = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

to this

$ADJUST_STMT_PREP = mysqli_stmt_bind_param($ADJUST_PREP, 'i', $pos_op);

Instead of this using mysqli_stmt_free_result():

mysqli_stmt_free_result($ADJUST_STMT_PREP);

Try used mysqli_stmt_get_result():

mysqli_stmt_get_result($ADJUST_STMT_PREP);

Try it now.

So everything you change

$ADJUST = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
$ADJUST_PREP = mysqli_stmt_prepare($connection, $ADJUST);
$ADJUST_STMT_PREP = mysqli_stmt_bind_param($ADJUST_PREP, 'i', $pos_op);

$pos = $_GET['pos'];
$pos_op = $pos + 1;

mysqli_stmt_execute($ADJUST_STMT_PREP);
mysqli_stmt_get_result($ADJUST_STMT_PREP);
mysqli_stmt_close($ADJUST_STMT_PREP);

It gets me the exact same error msg as before.

Very weird, because further down the same page, ia am runnning another prepared statement with the same connection variable, and having no problems. I just get an error in every attampt to use mysqli_stmt_etc_etc.. in this script:

$adjust             = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
$ADJUST_PREP        = mysqli_stmt_prepare($connection, $adjust);
$ADJUST_STMT_PREP   = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

$pos = $_GET['pos'];
$pos_op = $pos + 1;

mysqli_stmt_execute($ADJUST_STMT_PREP);

Is there someway to debug better, than mysqli_error,mysqli_stmt_error? As I dont see whats wrong with the statements..Is there something in my installation etc? All though there shuldnt be, as I am using PS throughout the entire system with no problems. Its only this one thats f...s up..

I think $pos_op should go before the statement, because it still doesn't exists and so this will give a boolean FALSE value when you try to send it to mysqli, so try to change the order:

$pos = $_GET['pos'];
$pos_op = $pos + 1;

$adjust             = "UPDATE modul_galleri SET pos = pos - 1 WHERE pos = ?";
$ADJUST_PREP        = mysqli_stmt_prepare($connection, $adjust);
$ADJUST_STMT_PREP   = mysqli_stmt_bind_param($ADJUST_PREP, "i", $pos_op);

bye!

I have found out what i did wrong..

I had saved the mysqli_stmt_bind_param in a variable, and then used that variable in the execute statement, instead of the actual stmt object that was created using mysqli_stmt_prepare. So basically I wasnt using the stmt object at all :-)

Thanks, for your time LastMitch!

/Klemme

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.