Jump to content

Recommended Posts

okay what's wrong with this query?

$sqladdlead = "UPDATE staff SET firstname = '".$leader['0']."' && surname = '".$leader['1']."' WHERE firstname = '" . $rowlead['firstname'] . "' && surname = '" . $rowlead['surname'] . "' && position = 'leader'";

Every time I run it the data isn't sent properly. It seems to set the firstname as 0 and doesn't change the surname at all..

I've tried echoing the statement to see what's wrong and it looks fine..

echo "UPDATE staff SET firstname = '".$leader['0']."' && surname = '".$leader['1']."' WHERE firstname = '" . $rowlead['firstname'] . "' && surname = '" . $rowlead['surname'] . "' && position = 'leader'";

and that outputs something like:

UPDATE staff SET firstname = 'Lindy' && surname = 'Bawtree' WHERE firstname = '0' && surname = 'Bawtree' && position = 'leader'

Which seems fine (obviously the "WHERE firstname ='0'" is because I've tried editing the database and it's set to 0 at the moment, because of this query..)

 

If someone can point out my problem I'd be thankfull. It's probably just a stupid mistake.

Thanks

You are incorrectly using &&, also, non numeric array indexes should not have there values surrounded by quotes. Try....

 

$sqladdlead = "UPDATE staff SET firstname = '".$leader[0]."', surname = '".$leader[1]."' WHERE firstname = '" . $rowlead['firstname'] . "' && surname = '" . $rowlead['surname'] . "' && position = 'leader'";

okay that query was sorted but now I'm having trouble with another UPDATE query..

$sql = "UPDATE staff SET mon = '" . $sday['mon'] . "', tues = '" . $sday['tues'] . "', weds = '" . $sday['weds'] . "', thurs = '" . $sday['thurs'] . "', fri = '" . $sday['fri'] . "', desc = '" . $desc . "' WHERE firstname = '" . $name['0'] . "' && surname = '" . $name['1'] . "'";

 

I get the message:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc = '' WHERE firstname = 'Susie' && surname = 'Campbell'' at line 1

 

So I guess it's the WHERE section that's wrong, but I don't see a problem with it.

Any help?

$sql = "UPDATE staff SET mon = '" . $sday['mon'] . "', tues = '" . $sday['tues'] . "', weds = '" . $sday['weds'] . "', thurs = '" . $sday['thurs'] . "', fri = '" . $sday['fri'] . "', desc = '" . $desc . "' WHERE firstname = '" . $name['0'] . "' AND surname = '" . $name['1'] . "'";

 

As I said earlier. Non numeric array keys should not be surrounded in quotes.

 

$name['0']

 

needs to be....

 

$name[0]

 

This makes perfect sense. Your code is looking for the string '0', accessing an array value with a string looks to php as though youve an associative array where in reality you dont.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.