mysql – PHP struggles. Error 404

05/02/2018


Trying to make a crud function/contact list. The user is brought to this page after they log in:


With a click of the edit function, I hope to take the user to a page that allows them to edit the contact details. Currently struggling to have the link function properly.

The link photo is my /view file. Which looks like this:

<?php 

session_start();

if(isset($_SESSION['u_uid'])){

$uid = $_SESSION['u_id'];

require_once('connect.php');
$ReadSql = "SELECT * FROM `contact` WHERE users_id=$uid ORDER BY Name";
$res = mysqli_query($connection, $ReadSql);

?>

<head>
<title>Motoko</title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" 
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

 <!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js">
</script>
</head>
<body> 
<div class="container">
    <div class="row">
    <table class="table">
        <tr>

            <th><strong>Name</strong></th>
            <th><strong>Company</strong></th>
            <th><strong>Title</strong></th>
            <th><strong>Phone</strong></th>
            <th><strong>Email</strong></th>
            <th><strong>Address</strong></th>
            <th><strong>Extras</strong></th>
        </tr>
        <?php 
        while($r = mysqli_fetch_assoc($res)){
        ?>
        <tr> 
            <td><?php echo $r['Name']; ?></td> 
            <td><?php echo $r['Company']; ?></td> 
            <td><?php echo $r['Title']; ?></td> 
            <td><?php echo $r['Phone']; ?></td> 
            <td><?php echo $r['Email']; ?></td> 
            <td><?php echo $r['Address']; ?></td> 
            <td><a href="crud/update.php?id=<?php echo $r['id'] ?>">Edit</a></td>
            <td><input type="button" onClick="deleteme(<?php echo $r['u_uid']; ?>)" name="Delete" value="Delete"></td>
             </tr>
 <!-- Javascript function for deleting data -->
 <script language="Javascript">
 function deleteme(delid)
 {
 if(confirm("Are you sure you want to Delete?")){
 window.location.href='crud/delete.php';
 }
 } 
 </script>
        <?php } ?>
    </table>
</div>
</body>

</html>

<?php

}else{

header("Location: http://motoko.sorainsurance.com.au"); 

}

?>

This would then take them to the /update file. Which starts like:

 <?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']);
    $comp =  mysqli_real_escape_string($connection,$_POST['comp']);
    $title =  mysqli_real_escape_string($connection,$_POST['title']);
    $phone =  mysqli_real_escape_string($connection,$_POST['urstel']);
    $email =  mysqli_real_escape_string($connection,$_POST['email']);
    $location =  mysqli_real_escape_string($connection,$_POST['location']);


  $UpdateSql = "UPDATE `contact` SET Name='$name', Company='$comp', 
Title='$title', Phone='$phone', Email='$email', Address='$location' WHERE id=$id"; 

    $res = mysqli_query($connection, $UpdateSql);
   if($res){
     echo $smsg = "Successfully updated data.";
     echo  header('location: view.php');
   }else{
     echo $fmsg = "Failed to update data.";
    }
}

Any idea why the error keeps popping up? So confused and struggling to progress 🙁

Many thanks!

قالب وردپرس