0

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!

Nickies
  • 13
  • 3

1 Answers1

0

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.

Tommy
  • 377
  • 1
  • 9
  • Thanks for your answer, but it isn't working. As i said, the problem is in the if-statement not in the query. – Nickies Mar 30 '16 at 08:03
  • Update your original code with the new and improved version, gives me and others a better idea of what could be wrong. – Tommy Mar 30 '16 at 09:15