-1

This little piece of code should be very easy basic coding, yet it doesn't work. The problem is within the INSERT / UPDATE code, because if I delete those and just echo simple text inside of the if/else code everything works just fine.

This is the code I have, whichs gives a HTTP ERROR 500.

$sql2 = mysqli_query($mysqli, "SELECT * FROM koppel WHERE userid = ".$_GET['userid']." AND msgid = ".$_GET['msgid']."");
$row = mysqli_fetch_assoc($sql2);

$check = $_GET['check'];                
$msgid = $_GET['msgid'];
$userid = $_GET['userid'];
$ja = 'ja';
$nee = 'nee';
$tabel_content = $row['check'];
$tabel_id = $row['id'];

if ($tabel_content == $ja){
    $stmt = $mysqli->prepare("UPDATE koppel SET check = ? WHERE id = ?");
    $stmt->bind_param('si',
       $nee,
       $tabel_id);
    $stmt->execute(); 
    $stmt->close();
} elseif ($tabel_content == $nee){
    $stmt = $mysqli->prepare("UPDATE koppel SET check = ? WHERE id = ?");
    $stmt->bind_param('si',
       $ja,
       $tabel_id);
    $stmt->execute(); 
    $stmt->close();
} else {
    $stmt = $mysqli->prepare("INSERT INTO koppel(userid, 
    msgid,check) VALUES (?, ?, ?)");
    $stmt->bind_param('iis', $userid, 
    $msgid,
    $check);
    $stmt->execute(); 
    $stmt->close();
}

What am I missing?

Jeffrey van Zwam
  • 105
  • 1
  • 15

1 Answers1

0

I don't see any error there, but make sure $mysqli is a valid mysqli connection to your database.

To debug your problem, try checking your server error logs (they will show the cause of your 500 error, and in which line) or try removing each part of your code until you understand exactly which line is failing.

You can also move all your "execute" and "close" calls to be below the if/elseif/else structure, as it always gets executed, to avoid repeating code.

Also "tabel" should be spelled "table".