bioTINMAN Posted December 26, 2007 Share Posted December 26, 2007 hi, im new to php and as well as this place, i was wondering if there was a way to replace: $insert=mysql_query("SELECT * FROM login where value1=5"); with: $value='value1=\'$val\' '; $insert=mysql_query("SELECT * FROM login where $value"); ------- the above thing works when we have something like $value='value1=5'; but when i insert a variable, there seems to be a problem. thanks! Quote Link to comment Share on other sites More sharing options...
trq Posted December 26, 2007 Share Posted December 26, 2007 What you have posted should work. You'll need to post your actual code if it is not working as expected. Quote Link to comment Share on other sites More sharing options...
neilfurry Posted December 26, 2007 Share Posted December 26, 2007 Can i see your actual code.. Quote Link to comment Share on other sites More sharing options...
bioTINMAN Posted December 26, 2007 Author Share Posted December 26, 2007 <?php if(mysql_connect(localhost,root,pass)) echo "in"; if(mysql_select_db(dump)) echo "into db"; $date=5; $TOTO='date=\'$date\''; echo $TOTO; $insert=mysql_query("SELECT * FROM login where $TOTO"); if($insert) echo "yes"; if($check=mysql_fetch_array($insert)) echo "yes again"; ?> ========== pardon the variable names, and those echo's - i was trying to check where the problem is. If i replace the $TOTO with date=5, it works. but with $TOTO it simply shuts off. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted December 26, 2007 Share Posted December 26, 2007 So why use $TOTO? Try: $TOTO = "date='$date'"; Quote Link to comment Share on other sites More sharing options...
bioTINMAN Posted December 26, 2007 Author Share Posted December 26, 2007 The idea is for a search form, one in which the user will choose some of the many fields on the page. I thought if i could use a variable like that of $TOTO, and keep adding field names into it, as the user choses them, then the mysql search query might be more compact. or is there another way? Quote Link to comment Share on other sites More sharing options...
jitesh Posted December 26, 2007 Share Posted December 26, 2007 Try this : $value = "value1='".$val."'"; $insert=mysql_query("SELECT * FROM login where ".$value); Quote Link to comment Share on other sites More sharing options...
bioTINMAN Posted December 26, 2007 Author Share Posted December 26, 2007 thanks! it worked. 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.