Jump to content

problem with my mysql query. Not setting data correctly


Dragen

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.