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 为什么我按照电路图做出的仿真和实物都不能使用
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面
  • ¥15 算法题:数的划分,用记忆化DFS做WA求调
  • ¥15 chatglm-6b应用到django项目中,模型加载失败
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web