Dragen Posted May 22, 2007 Share Posted May 22, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/ Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-258942 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 haha, thanks. I knew I was being stupid.. I haven't used the update much and forgot to use ',' instead of '&&'. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-258950 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-258971 Share on other sites More sharing options...
jitesh Posted May 22, 2007 Share Posted May 22, 2007 $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'] . "'"; Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-258975 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 nope. You can use both '&&' and 'AND' for a mysql query. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259000 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259003 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 thanks thorpe, but that doesn't change anything. still the same error. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259008 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 Echo the query and show us the output. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259018 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 it seems to echo fine: UPDATE staff SET mon = '1', tues = '1', weds = '1', thurs = '1', fri = '1', desc = '' WHERE firstname = 'Susie' && surname = 'Campbell' I don't see a problem with that.. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259057 Share on other sites More sharing options...
trq Posted May 22, 2007 Share Posted May 22, 2007 Are you sure desc can handle an empty string? Other than that, I don't see any issue. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259066 Share on other sites More sharing options...
Dragen Posted May 22, 2007 Author Share Posted May 22, 2007 It should be able to it's just a varchar, but I've also tried it with desc as a value as well but it still doesn't work. Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-259069 Share on other sites More sharing options...
Dragen Posted May 24, 2007 Author Share Posted May 24, 2007 figured it out! quite silly really.. it's the desk name for my table row. I can't use desk as it's a reserved name, so I've just put it as `desc`, which works absolutely fine... Thanks Quote Link to comment https://forums.phpfreaks.com/topic/52478-problem-with-my-mysql-query-not-setting-data-correctly/#findComment-260661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.