0

I'm trying to update a few users after I entered into their profile.

This is the button to transfer me to their profile page. Everything works fine until I try to update some info.

echo "<td>" .'<a  href="profile.php?id=' . $row['id']. '"><button class="view">View Profile</button></a>'. "</td>";

This is the profile page:

  $id = $_GET['id'];
  $db = mysqli_connect('localhost', '###', '###', '###');
  $sql = "SELECT * FROM clients  WHERE id='".$id."'  ";

  $result = mysqli_query($db, $sql);

    $resultCheck = mysqli_num_rows($result);

    if ($resultCheck > 0) {

    echo "<table>
            <tr>
                <th> Naam </th>
                <th> id </th>
                <th> email </th>

            </tr>";
        while ($row = mysqli_fetch_assoc($result)) {
      echo "<tr>";
            echo  "<td>" . $row['name'] . "</td>";
            echo  "<td>" . $row['id'] . "</td>";
            echo "<td>" . $row['email']  . "</td>";   

            $name = $row['name'];
            $email = $row['email'];

    }
  }  

    if (isset($_POST['pinfo'])) {

      $query = "UPDATE clients SET name=? , email=?
       WHERE id=?";
      $stmt = mysqli_prepare($db, $query);
      mysqli_stmt_bind_param($stmt, 'sss',   $_POST['name'], $_POST['email'], $id);
      mysqli_stmt_execute($stmt);
   }

After trying to update I just get an error of "Undefined index: id"

Hamid Naghipour
  • 3,465
  • 2
  • 26
  • 55

1 Answers1

0

your id field is not initialized or for some reason rest. try passing the id with the form by setting it to a hidden form element like:

<input stype="diplay: none;" name="id" value='"+$id+"' />

and passing it to mysql_stmt_bind_param from $_POST like

 mysqli_stmt_bind_param($stmt, 'sss',   $_POST['name'], $_POST['email'], $_POST['id']);
Mike Araya
  • 155
  • 1
  • 11