Jump to content

display data directly into forms using php(data retrived from mysql db


csakthikumar

Recommended Posts

<?php
$result = mysql_query("SELECT * FROM user WHERE id='123'");
$row = mysql_fetch_assoc($result);
?>
<form>
name: <input type="text" name="name" value="<?php print (strlen($_POST['name']) ? $_POST['name'] : $row['name']); ?>" /><br />
email: <input type="text" name="email" value="<?php print (strlen($_POST['email']) ? $_POST['email'] : $row['email']); ?>" /><br />
</form>

 

Get the idea? If the form is submitted with new data and there are errors (you will have to validate the input) the fields will retain the new data entered, otherwise they will display the default values from the database. However I would not recommend putting POST data back into an input field until it has been sanitized i.e. remove sql injection, html, javascript, etc

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.