Herbert at GC Posted April 2, 2011 Report Share Posted April 2, 2011 Hi guys this topic is from video tutorial (Complete web programing)"PHP CRUD". From video tutorial "php_crud" -- videos: mysqli-2 "view.php" and mysqli- "delete.php" Problem: Can't delete a record (please help codes below). delete.php code =========================================================== <?php include('db-connect.php'); if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; if($stmt = $mysqli->prepare("DELETE FROM records WHERE id = ? LIMIT 1")) { $stmt->bind_param("i",$id); $stmt->execute(); $stmt->close(); } else { echo "Error: Could not prepare sql etatement"; } $mysqli->close(); header("Location: view.php"); } else { header("Location: view.php"); } ?> =================================================================== view.php code =================================================================== <?php include('db-connect.php'); if ($result = $mysqli->query("SELECT * FROM records ORDER BY id")) { if($result->num_rows > 0); { echo "<table border='1' cellpadding='10'>"; echo "<tr><th>ID</th><th>First Name</th><th>Last Name</th><th></th><th></th></tr>"; while ($row = $result->fetch_object()) { echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->firstname . "</td>"; echo "<td>" . $row->lastname . "</td>"; echo "<td><a href='records.php?id" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id" . $row->id . "'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } } else { echo "Error: " . $mysqli->error; } $mysqli->close(); ?> Thanks, Herbert Quote Link to comment Share on other sites More sharing options...
falkencreative Posted April 2, 2011 Report Share Posted April 2, 2011 So what currently happens when you run this code? An error message? A blank screen? Quote Link to comment Share on other sites More sharing options...
falkencreative Posted April 2, 2011 Report Share Posted April 2, 2011 One thing to double check that I found when looking over your code... Take a look at these lines in your view.php: echo "<td><a href='records.php?id" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id" . $row->id . "'>Delete</a></td>"; I'm pretty sure it is supposed to be: echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>"; (note the "="). Quote Link to comment Share on other sites More sharing options...
Herbert at GC Posted April 2, 2011 Author Report Share Posted April 2, 2011 Noting happens no errors or anything. I'll change the code on view.php. Thanks Ben One thing to double check that I found when looking over your code... Take a look at these lines in your view.php: echo "<td><a href='records.php?id" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id" . $row->id . "'>Delete</a></td>"; I'm pretty sure it is supposed to be: echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>"; (note the "="). Quote Link to comment Share on other sites More sharing options...
falkencreative Posted April 2, 2011 Report Share Posted April 2, 2011 Let me know. I'm guessing that fixing the "=" issue should take care of things. Without the "=", you aren't setting the proper variables and your delete/edit links won't work. Quote Link to comment Share on other sites More sharing options...
Herbert at GC Posted April 3, 2011 Author Report Share Posted April 3, 2011 Ben bro I hate to say this, but it works! Thanks again, Herbert Let me know. I'm guessing that fixing the "=" issue should take care of things. Without the "=", you aren't setting the proper variables and your delete/edit links won't work. Quote Link to comment Share on other sites More sharing options...
falkencreative Posted April 3, 2011 Report Share Posted April 3, 2011 Good, glad to hear that it's working properly. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.