Jump to content

WHERE clause wont use variables with spaces.


UrbanDweller

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.