douxie1894 2014-05-19 14:17
浏览 62
已采纳

SQL语句中的多个PHP变量的问题

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 ."' ");

with

$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());
  • 写回答

1条回答 默认 最新

  • dongmaoxi0477 2014-05-19 14:24
    关注

    You are emptying $SC3 in the if condition.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?