Jump to content

Assignments in conditions


CLU

Recommended Posts

Hi Guys,

 

Just quick one, I completed ben's tut on CRUD with mysqli, within my editor (Netbeans) when using bind_param in regards to the used question marks for the values, i get a small warning stating "Possible accidental assignment, assignments in conditions should be avoided."

 

Code works fine, but can anyone explain what this might mean?

 

Any guidance on this would be appreciated.

 

Kind Regards.

Link to comment
Share on other sites

You'd have to post the code for me to be sure, but I believe it's complaining about lines like this:

 

if ($stmt = $mysqli->prepare("UPDATE players SET firstname = ?, lastname = ?
                                               WHERE id=?"))

You can safely ignore that warning, or rewrite it slightly:

 

$stmt = $mysqli->prepare("UPDATE players SET firstname = ?, lastname = ?
                                               WHERE id=?");
if ($stmt)

 

It's just that Netbeans is seeing the = within a if statement, and thinking that maybe you made a mistake and you meant to say "==" or another comparison operator. I believe you should be able to disable this warning if you want: http://forums.netbeans.org/topic8214.html

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...