dtp791357 2015-03-07 05:12
浏览 33
已采纳

sql语句中的逻辑

connect1($db_host,$db_username,$db_password,$db_name1);

$q="SELECT DISTINCT
bizinfo.dbiz_id,
bizinfo.company_name,
bizinfo.company_industry,
bizinfo.company_sub_industry
FROM
bizinfo
Inner Join biz_feedback ON bizinfo.dbiz_id = biz_feedback.biz_id AND biz_feedback.on_industry = bizinfo.company_industry
ORDER BY
bizinfo.dbiz_id ASC";
$rs_q=mysql_query($q);
while($row=mysql_fetch_assoc($rs_q))
{
$dbiz_id=$row['dbiz_id'];
$company=$row['company_name'];
$company_industry=$row['company_industry'];
$company_sub_industry=$row['company_sub_industry'];

connect2($db_host,$db_username,$db_password,$db_name2);

$sql_livedb=mysql_query("UPDATE bizinfo set bizinfo.company_industry='$company_industry', bizinfo.company_sub_industry='$company_sub_industry'
WHERE bizinfo.dbiz_id='$dbiz_id'");
}

When this code is run, all rows in the company_industry and company_sub_industry columns are filled with the same data (for the first biz_id).

Somewhere a join needs to happen, but I thought I had it covered here WHERE bizinfo.dbiz_id='$dbiz_id'.

  • 写回答

1条回答 默认 最新

  • dongmo8943 2015-03-07 07:59
    关注

    It isn't at all obvious what your problem is, but I would guess that there is a value in one of the variables (probably $company_sub_industry) which has a single quote embedded in it, and consequently results in the WHERE clause being ignored.

    Change your code to remove the update statement and instead dump the values so you can check them. Perhaps some error checking after/in mysql_query would help.

    If this is the cause, the real solution is to not generate SQL by concatenating strings and variables. Research "php avoid SQL injection" for more info.

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

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug