i have this script to connect my DB and i get error 500 when using it.
I tried to track where the error is and i think its at this line: while ($row = $stmt->fetch_assoc())
But i looked over examples and its the same is mine.
Here is my code thanks for helping:
<?php
$mysqli = new mysqli(*MY DB DETAILS*);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$sql = "SELECT * FROM comments WHERE workout_name =? AND user =?";
$stmt = $mysqli->prepare($sql) or trigger_error($mysqli->error."[$sql]");
$stmt->bind_param('ss', $workout_name, $user);
$workout_name = $_GET['workout_name'];
$user = $_GET['user'];
$stmt->execute();
if ($stmt)
{
while ($row = $stmt->fetch_assoc())
{
$response["name"] = $row["workout_name"];
echo json_encode($response);
}
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
}
else
{
$response["success"] = 2;
// echoing JSON response
echo json_encode($response);
}
?>
UPDATE:
I had to change $row = $stmt->fetch_assoc()
as described here: