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

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.

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

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了