Got a table with client data. Trying to incorporate an edit function. Currently, the table has a <a href>
for the "edit" link.
<tr>
<th><strong>Extras</strong></th>
</tr>
<?php while($r = mysqli_fetch_assoc($res)){
?>
<tr>
<td><a href="crud/update.php?id='.$r['id'].'">Edit</a></td>
<td><input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete"></td>
</tr>
function deleteme(delid)
{ if(confirm("Are you sure you want to Delete?")){
window.location.href='crud/delete.php';
}
}
</script>
<?php } ?>
note that:
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);
I hoped to take the user to the crud/update.php which starts as:
<?php
error_reporting();
require_once('connect.php');
$id = $_GET['id'];
$SelSql = "SELECT * FROM `contact` WHERE id=$id";
$res = mysqli_query($connection, $SelSql);
$r = mysqli_fetch_assoc($res);
if(isset($_POST) & !empty($_POST)){
$name = mysqli_real_escape_string($connection,$_POST['name']);
//and other credentials
$UpdateSql = "UPDATE `contact` SET Name='$name', Company='$comp',
Title='$title', Phone='$phone', Email='$email', Address='$location' WHERE id=$id";
Pulling my hair out because I can't find why I get an error every time I press the "edit" link.
Cheers guys.
The reason you are getting 404 is that you did not have proper link.
You have mixed HTML and PHP on line
<a href="crud/update.php?id='.$r['id'].'">Edit</a>
It should be:
<a href="crud/update.php?id=<?php echo $r['id'] ?>">Edit</a>