2014-05-19 14:17



My problem is i am trying to get 3 variables from the URL, they echo the correct information so i know that my $_GET's are working fine, The first $SC1 and $SC2 both work fine but the 3rd one in the SQL statement Dosnt.

If i replace

$thestatement = ("SELECT * FROM asset_records  WHERE a_catagory = '".$SC1."' AND ".$SC2." = '". $SC3 ."' ");


$thestatement = ("SELECT * FROM asset_records  WHERE a_catagory = '".$SC1."' AND ".$SC2." = 'apple' ");

it works fine but i know $SC3 = apple because i can echo the variable and its apple, please help im pulling my hair out. Heres the rest of the code regarding this.

Note: This is a search function that basis itself on which link people click in my websites menu and takes into consideration when people first click on the website so it displays all items in it.

require ('..\connect_db.php') ;

$SC1 = mysql_real_escape_string($_GET['sc1']); echo $SC1; 
$SC2 = mysql_real_escape_string($_GET['sc2']); echo  $SC2;
$SC3 = mysql_real_escape_string($_GET['sc3']); echo $SC3;

if ($SC1 && $SC2 && $SC3 = '') {

$thestatement = ('SELECT * FROM asset_records');}

else  {;

$thestatement = ("SELECT * FROM asset_records  WHERE a_catagory = '".$SC1."' AND ".$SC2." = '". $SC3 ."' ");


$result = mysql_query('' .$thestatement. '') or die(mysql_error());
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongmaoxi0477 dongmaoxi0477 7年前

    You are emptying $SC3 in the if condition.

    点赞 评论 复制链接分享