Hey guys, I am working on a webpage and I don't know why I can't update a value from my database and display it.
This is my code for the PHP page to display the link. When clicked it will call another PHP program to do the update and then be redisplayed in the display PHP program.
echo "<td class='text pad center'>".$row['deleted']." </td>";
if ( $row['deleted'] == 'y' ) {
echo '<td class="text center"><a href="delete.php?id='.$row["id"].'">Restore</a>; </td>';
} else {
echo '<td class="text center"><a href="delete.php?id='.$row["id"].'">Delete</a>; </td>';
}
And in my update program I have this code that will perform the update in my database and then send the new value to be redisplayed.
$id=$_GET['id'];
$sql_query = "SELECT * FROM tablename WHERE id = '$id'";
//Run our sql query
$result = mysqli_query($link, $sql_query) or die('select query failed'. mysqli_error($link));
while ($row = mysqli_fetch_assoc($result)) {
if ( $row['deleted'] == 'y' ) {
$change = "UPDATE inventory SET DELETED = 'n' WHERE id = '$id'";
} else {
$change = "UPDATE inventory SET DELETED = 'y' WHERE id = '$id'";
}
echo "$change";
mysqli_query($link, $change) or die('select query failed'. mysqli_error($link));
}
//Free resultset (optional)
mysqli_free_result($result);
//Close the MySQL Link
mysqli_close($link);
header("Location: display.php");
I can't find my error.
yandnfor boolean values, use1and0[trueandfalserespectively].