Jump to content

session variables in a form


bhavin_85

Recommended Posts

hey guys

 

i want to create a form that updates a users account details...is there a way that i can get the form to show the users current details in each text box? then the user clicks on that box to edit the deails?

 

also how would i structure a query so that it only updates the edited fields? and keeps the rest the same?

 

i had a good at creating some code but get a parse code

 

<tr>
<td>
<?php
<form name="account_edit" method="post" action="page2.php">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td> </td>
            <td> </td>
            <td colspan="2"> </td>
          </tr>
          <tr>
            <td height="40"><div align="right"><span class="style1">Field you want to edit </span></div></td>
            <td width="28" height="40"> </td>
            <td height="40" colspan="2"><input name="field" type="text" id="songtitle" size="20" value="$date" ></td>
          </tr>
          <tr>
            <td height="53"> </td>
            <td width="28" height="53"> </td>
            <td width="83" height="53"> </td>
            <td width="157"><div align="left">
              <input type="submit" name="Submit" value="Edit" />
            </div></td>
          </tr>
        </table>
        </form>
	?>
</td>
</tr>

parse error is because the <form> is inside the <?Php

Link to comment
https://forums.phpfreaks.com/topic/41269-session-variables-in-a-form/
Share on other sites

actually come to think of it, you should perform a query at the beginning of the user details page and use the results for field values

 

i.e.

$user_id = $_SESSION['user_id'];

$sql = "SELECT * from `users` WHERE `id`='$user_id'";

$result = mysql_query($sql);

$row = mysql_fetch_object($result);

 

<input type="text" name="user_name" value="<?=$row->user_name;?>">

the second way you suggested didnt work, the first way is fine though it does the trick

 

got 1 other issue though, the page shows the customer date of birth

 

how do i get it to print the date as dd/mm/yyyy

 

ive turned the date into $date as a variable

 

value="<?('j/n/Y',strtotime($date));?>"

 

the other problem i can think of is if they change their date of birth (say it was entered wrong) would they have to enter it as yyyy/mm/dd as thats the way its stored inthe database?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.