ili
ili

Reputation: 139

Update MySQL entries via PHP/Html & sql

Im trying to create a form where based on someones first and surname, their email can be changed.

So the html looks like this:

<form action="sUpdateResponse.php" method="post">
<input type="text" placeholder="Enter Email..." name="sUpdateEmail">
Where the name is 
<input type="text" placeholder="Enter Forename..." name="sUpdateFN">
<input type="text" placeholder="Enter Surname..." name="sUpdateSN">
    <input type="submit" value="Update Records" name="sRetrieveUpdate"></form>  

This takes a new email to update the data entry where the forename and surname exist.

The php on sUpdateResponse looks like this,

if($_POST['sRetrieveUpdate']) 
    $queryRetrieve = mysql_query( "UPDATE staffData SET sEmail='".$_POST['sUpdateEmail']."' WHERE sFN='".$_POST['sUpdateFN']."' 
    AND sFN='".$_POST['sUpdateSN']."'" );

This doesn't return an error but doesn't seem to alter the email either...

Where am i going wrong?

Upvotes: 0

Views: 118

Answers (3)

Developer
Developer

Reputation: 7

Your Second column is same in where condition sFn repeated. WHERE sFN='".$_POST['sUpdateFN']."' AND sFN='".$_POST['sUpdateSN']."'")

It cheks two values in same column . There is your column name mistake in the query.make it correct then it will work fine :)

It should be Something like this if($_POST['sRetrieveUpdate']) $queryRetrieve = mysql_query( "UPDATE staffData SET Email='".$_POST['sUpdateEmail']."' WHERE sFN='".$_POST['sUpdateFN']."' AND sSN='".$_POST['sUpdateSN']."'" );

Upvotes: 0

Hardik Bharadava
Hardik Bharadava

Reputation: 472

<?php
if(isset($_POST['sRetrieveUpdate'])){
      if(isset($_POST['sUpdateEmail']) && isset($_POST['sUpdateFN']) && isset($_POST['sUpdateSN'])){
            $query = "UPDATE staffData SET sEmail = '.$_POST['sUpdateEmail'].' WHERE sFirstName = '.$_POST['sUpdateFN'].' AND sSurName = '.$_POST['sUpdateSN']";
            $Result = mysqli_query($query);
      }else{
            // Error Message
      }
}else{
      // Error Message
}
?>

Upvotes: 1

Tanmoy Roy
Tanmoy Roy

Reputation: 1

"UPDATE staffData SET sEmail='".$_POST['sUpdateEmail']."' WHERE sFN='".$_POST['sUpdateFN'].$_POST['sUpdateSN']."'"

Upvotes: 0

Related Questions