0

I understand the title is pretty ambiguous so let me explain in more detail. I am using PHP to output a form which will display certain user information, the information is that which the user had previously stored in the database. This part of the code is working fine and the data is being displayed as I wish. Once the data is displayed in the input boxes, I want the user to be able to edit the information and then once the user clicks the submit button the updateuserinfo.php script will be called:

    while($return = mysql_fetch_assoc($result)) {
    echo "<form action=UpdateUserInfo.php method=post>";
    echo "<p> First Name: <input type=text name=firstname value= ".$return['FirstName']."/></p>";
    echo "<p> Surname: <input type=text value= ".$return['Surname']." /></p>";
    echo "<p> House Number: <input type=number value= ".$return['HouseNumber']." /></p>";
    echo "<p> Address Line One: <input type=text value= ".$return['AddressLineOne']." /></p>";
    echo "<p> Address Line Two: <input type=text value= ".$return['AddressLineTwo']." /></p>";
    echo "<p> County: <input type=text value= ".$return['County']." /></p>";
    echo "<p> Phone Number: <input type=number value= " .$return['PhoneNumber']." /></p>";
    echo "<p> Email: <input type=email value= ".$return['Email']." /></p>";
    echo "<p> Username: <input type=text value= ".$return['Username']." /></p>";
    echo "<p> Password: <input type=password value= ".$return['Password']." /></p>";
    echo "<p> User Type: <input type=text value= ".$return['UserType']." /></p>";
    echo "<input id=submit type=submit value='Update Info' Info />";
    echo "</form>";

In the script found in updateuserinfo.php I was hoping I could firstly display the users info i.e what the user has changed the input box values to and then update the database if the user confirms the changes. I am confident I will be able to update the information stored on the database as this is a simple SQL query but the problem I am having is that I can not display the information found in the input boxes when the user has made changes. I thought I could apply a name attribute to each input tag, like I have done with 'firstname' and then use:

    echo "<p>First Name: " $_POST[firstname] "</p>";

in the updateuserinfo.php in order to display the information the user has entered in the input box. However this is not working. Any suggestions would be greatly appreciated as I'm extremely new to programming in PHP. Thanks in advance.

user3298004
  • 185
  • 2
  • 3
  • 10
  • Please do `print_r($_REQUEST)`... – MarcoS Feb 13 '14 at 13:23
  • You are generating the form within a loop are u sure that it returns data for one user not multiple ? if just one User then by using $_POST["firstname"] would return the data being posted !! – Abhik Chakraborty Feb 13 '14 at 13:27
  • @JaGO I have made all the changes suggested in the answers and my output for the statement here: echo "

    First Name: " . $_POST["firstname"] . "

    "; is shown here: First Name: " . $_POST["firstname"] . " "; ?> so clearly the post function is not working correctly but I am not sure why. Any ideas what could be the problem? Thanks again
    – user3298004 Feb 14 '14 at 16:52

2 Answers2

0

You should read $_REQUEST array, not $_POST...

UPDATE

Sorry, I did never use $_POST... It has been introduced in 4.1.0. So, only check your PHP version is >= 4.1.0... Otherwise please post

print_r($REQUEST);

results...

MarcoS
  • 17,323
  • 24
  • 96
  • 174
0

Try to show the complete $_POST array by using this code: var_export($_POST);

Also you are missing some quotes in your Form. For example the line

echo "<p> First Name: <input type=text name=firstname value= ".$return['FirstName']."/></p>";

should be

echo "<p> First Name: <input type=\"text\" name=\"firstname\" value=\" ".$return['FirstName']."\"/></p>";

or easier within single quotes (so you don't have to mask each double quote):

echo '<p> First Name: <input type="text" name="firstname" value= "'.$return['FirstName'].'"/></p>';

Read What is the difference between single-quoted and double-quoted strings in PHP? if you want to know what's the difference between single and double quotes in PHP

And in your update Script you are missing the dot operator and also the quotes:

echo "<p>First Name: " $_POST[firstname] "</p>";

should be

echo "<p>First Name: " . $_POST["firstname"] . "</p>";
Community
  • 1
  • 1
JaGo
  • 172
  • 1
  • 9
  • thanks for the help, although I'm still a little confused and would like to understand this situation better. I have made the changes to the quotes in the form and I understand the difference between single and double quotes now (thanks for the link). But var_export($_POST)? what exactly does this do? should it be part of my update script or part of the script outputting the original form? – user3298004 Feb 13 '14 at 21:16
  • var_export($_POST); will print out all the content of your $_POST array. This is just for debugging, you do not have to use it in your running scripts. Have a look at http://www.php.net/manual/en/function.var-export.php for more details – JaGo Feb 17 '14 at 16:12