csakthikumar Posted July 9, 2009 Share Posted July 9, 2009 GUYS i want to display data into forms which includes buttons,text box and list box using php where data is retrived from mysql db i just want to retrieve the datas already stored in db and make it editable.. please help......... Quote Link to comment https://forums.phpfreaks.com/topic/165360-display-data-directly-into-forms-using-phpdata-retrived-from-mysql-db/ Share on other sites More sharing options...
JonnoTheDev Posted July 9, 2009 Share Posted July 9, 2009 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/165360-display-data-directly-into-forms-using-phpdata-retrived-from-mysql-db/#findComment-872065 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.