dongmou5628 2016-03-29 14:16
浏览 26

MySQL和PHP | 选择后更新不起作用

I have this weird situation where my query isn't doing what it's supposed to do.

Here is my not working code:

$aanbodID = 1;
$db = //connection

$getData = $db->query("SELECT boekbaar_iframe FROM aanbod_20160206 WHERE id_aanbod=$aanbodID") or die(mysql_error());
while ($row_content = mysql_fetch_array($getData)) 
{       
    $zichtbaarjanee = $row_content['boekbaar_iframe']; // 0 or 1
}

if ($zichtbaarjanee == 0)
{
    $nieuwewaarde = 1;
}else{
    $nieuwewaarde = 0;
}

db->query("UPDATE aanbod_20160206 SET boekbaar_iframe = '$nieuwewaarde' WHERE id_aanbod = '$aanbodID'");
echo mysql_error();

And here is almost the same code that is working:

 $aanbodID = 1;
$db = //connection

$getData = $db->query("SELECT boekbaar_iframe FROM aanbod_20160206 WHERE id_aanbod=$aanbodID") or die(mysql_error());
while ($row_content = mysql_fetch_array($getData)) 
{       
    $zichtbaarjanee = $row_content['boekbaar_iframe']; // 0 or 1
}

//switch these vars and its working    
$nieuwewaarde = 0;
// $nieuwewaarde = 1; 

db->query("UPDATE aanbod_20160206 SET boekbaar_iframe = '$nieuwewaarde' WHERE id_aanbod = '$aanbodID'");
echo mysql_error();

So i'm guessing the problem is somewhere in the if statement, but i've tried everything, also with and without ' ' or " ".

update: changed querys to mysqli_*

the problem is still in the if/else statement

because this is working:

//if ($zichtbaarjanee == 0)
//{
//  $nieuwewaarde = 1;
//}else{
    $nieuwewaarde = 0;
//}

When I switch the 0 for a 1 it's also working, but when i comment in the piece of code it stops updating the table

Please help!

  • 写回答

1条回答 默认 最新

  • drcb19700 2016-03-29 15:50
    关注

    Every instance of MySQL needs to be replaced with MySQLi As it was deprecated in PHP 5.5.

    http://php.net/manual/en/book.mysqli.php

    And trying to concatenate:

    mysql_query("UPDATE aanbod_20160206 SET boekbaar_iframe = ".$nieuwewaarde." WHERE id_aanbod = ".$aanbodID.""); 
    

    Should be changed to:

    mysqli_query("UPDATE aanbod_20160206 SET boekbaar_iframe = '$nieuwewaarde' WHERE id_aanbod = '$aanbodID'");
    

    I understand you're trying to embed the variable in the query, however in this case it would just add 2 dots on either side of your variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集