UrbanDweller Posted December 23, 2011 Share Posted December 23, 2011 Hey, Like my title says I cant get a mysql update to fetch and update row depending on what the where clause is equal too. it updates fine if the variable is one word but 2+ words it just doesnt input the data. $num=0; foreach($_SESSION['colid'] as &$id){ if($num > 2){ $data = $_POST[$id]; mysql_query("UPDATE `$table` SET `$colname`='$data' WHERE Unit='$id'") or die("error".mysql_error()); } $num++; $_SESSION['colid'] is an array of all the table column names which i have made the same for each row of data under Unit. so wen $id = word, it updates fine but $id = two words, it wont update. Ive tried `$id` | '`$id `' | ('$id') pretty much everything thats worked before. Is this fixable or do i need to create columns with underscores instead of spaces eg. two_words then use a php function to swap _ to a space? Thanks Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 I don't see $colname assigned a value anywhere. Are you getting any errors returned by MySQL? Do you have error reporting set up properly in php? Quote Link to comment Share on other sites More sharing options...
UrbanDweller Posted December 23, 2011 Author Share Posted December 23, 2011 Hey all the variables are valid and not empty its just that it seems that "WHERE `unit`='$id' " doesnt like $id to be two words with a spaces thats the ONLY problem. Im not going to post the whole code in as the rest of the code works fine when using single word variable $id. I have change a single word column that works fine and changed it to two words which it will then not input the data in the update query. i just want to know how to allow it to use it. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 23, 2011 Share Posted December 23, 2011 I didn't ask you to post all of the code, and you didn't answer my questions. Good luck with it. Quote Link to comment Share on other sites More sharing options...
UrbanDweller Posted December 23, 2011 Author Share Posted December 23, 2011 http://www.youtube.com/watch?NR=1&feature=endscreen&v=hTP31OTZxtU Quote Link to comment Share on other sites More sharing options...
fenway Posted December 24, 2011 Share Posted December 24, 2011 I have no idea what you're talking about. Echo the actual queries, and we'll see if anyone can help. Quote Link to comment Share on other sites More sharing options...
ElmoTheClown Posted December 24, 2011 Share Posted December 24, 2011 Is it ever a good idea to use a query in a loop? Quote Link to comment Share on other sites More sharing options...
fenway Posted December 25, 2011 Share Posted December 25, 2011 Is it ever a good idea to use a query in a loop? For update, it's often required -- but without seeing the statements, I can't be certain. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted December 26, 2011 Share Posted December 26, 2011 Since the OP's code is skipping the query code during the first three iterations of the loop, it's likely that the query(ies) that are not updating anything correspond to those first three iterations of the loop. Quote Link to comment 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.