Jump to content

How do I edit a record in a database, or enter data from a database into a form?


IChaps

Recommended Posts

Hello.

 

Could I please request some guidance with editing data?

 

I'm looking to build a form, which will pull data from a database and display it in the form, so it can be edited.

However I don't know the correct way to enter the data into the form.

 

or, I'll ask the question another way :)

How do I edit a record held in a database please?

 

Thank you.

Link to comment
Share on other sites

You edit records using the UPDATE statement: http://www.w3schools.com/sql/sql_update.asp

 

To put data into a form, pull the data out of the database using an ordinary SELECT query, then print the values into the value attribute of the input element.

<input type="text" name="fname" value="<?php echo $data['first_name']; ?>">
Link to comment
Share on other sites

Hello again.

 

I've tried the suggestion above, however I can't get it to work, as I'm getting a blank field.

I have also written the code below, and I'm still getting a blank field next to the Account Name.

 

Could I please request if anyone could write the correct coding for me?

Thank You.

 

 

 

<div id="editform">
<form name="edit_account" action="EDITING" method="POST">
<table style="border-size: 0px">
<tr>
<td width="25%">Account Name:</td>
<td width="11%"></td>
<td> <input name="profile_fullname" value= "<?php echo $_SESSION['$member_Fullname']; ?>" maxlength="20"></td>
</tr>
<tr>
<td width="25%">Username:</td>
<td width="11%"></td>
<td><input name="profile_username" value=$username maxlength="20"></td>
</tr>
<tr>
<td width="25%">EMail:</td>
<td width="11%"></td>
<td><input name="profile_email" type="text" value="mememail"></td>
</tr>
<tr>
<td width="25%">Password:</td>
<td width="11%"></td>
<td>*****</td>
</tr>
<tr>
<td width="25%">Location:</td>
<td width="11%"></td>
<td><input name="profile_location" type="text" value="location" maxlength="20"></td>
</tr>
<tr>
<td width="25%">Country:</td>
<td width="11%"></td>
<td><select name="country" size="1">
<option selected="selected">United Kingdom</option>
</select> ></td>
</tr>
<tr>
<td width="25%">DOB:</td>
<td width="11%"></td>
<td> <?php $_SESSION['$member_DOB']; ?> </td>
</tr>
<tr>
<td width="25%">Gendar:</td>
<td width="11%"></td>
<td><select name="gender" size="1">
<option>Male</option>
<option>Female</option>
</select></td>
</tr>
<!-- <tr>
<td width="25%">Profile Photo:</td> memphoto
<td width="11%"></td>
<td>Form Basic 9</td>
</tr> -->
<tr>
<td width="25%">Time Zone:</td>
<td width="11%"></td>
<td><select name="timezone" size="1">
<option>GMT</option>
</select></td>
</tr>
<tr>
<td width="25%">Website URL:</td>
<td width="11%"></td>
<td><textarea name="profile_websiteurl" value="website"> </textarea> </td>
</tr>
<!-- <tr>
<td width="25%">Membership Type:</td> memtype
<td width="11%"></td>
<td> <?php $_SESSION['$member_MembershipType']; ?></td>
</tr>
<tr>
<td width="25%">Account Status:</td> memstatus
<td width="11%"></td>
<td><?php $_SESSION['$member_AccountStatus']; ?></td>
</tr> -->
<tr>
<td width="25%">Short URL:</td>
<td width="11%"></td>
<td><input name="profile_shorturl" value="$shorturl"></td>
</tr>
<tr>
<td width="25%">Business Address:</td>
<td width="11%"></td>
<td> <textarea name="profile_businessaddress"> </textarea> </td>
</tr>
<tr>
<td width="25%">Date Joined:</td>
<td width="11%"></td>
<td> <?php $_SESSION['$member_SignupDate']; ?> </td>
</tr>
<tr>
<td width="25%">Last Visited:</td>
<td width="11%"></td>
<td><?php $_SESSION['$member_LastVisitDate']; ?></td>
</tr>
</table>
</form>
</div>

Link to comment
Share on other sites

The following might be useful

 

Example to Add Data to SQL
UPDATE Customers
SET ContactName='Alfred Schmidt', City='Hamburg'
WHERE CustomerName='Alfreds Futterkiste';
Try it Yourself »
Example to delete a data in SQL
DELETE FROM Customers
WHERE CustomerName='Alfreds Futterkiste' AND ContactName='Maria Anders';
Try it Yourself »
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...