0

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?

3

3 Answers 3

1
<?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
}
?>
Sign up to request clarification or add additional context in comments.

4 Comments

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in || $query line
I was forgot to put " surrounding to $_POST['sUpdateEmail'] Just put " surrounding it. Like, ".$_POST['sUpdateEmail']." with all three Posting Value.
Warning: mysqli_query() expects at least 2 parameters, 1 given
@ili, Are you using OO Style or Procedural Style? You may refer here to get Solution of this, both the options are here. you may easily solve it. :)
0

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

Comments

0

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']."'" );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.