daverichris Posted April 8, 2011 Share Posted April 8, 2011 Hello, I am trying to populate the value="" of my form with the data from the mysql database so users can see what is already completed, trial and error have failed me. what am i doing wrong? <?php session_start(); include 'english.php'; if (!isset($_SESSION['user'])) die("<br /><br />You need to login to view this page"); $user = $_SESSION['user']; echo "<h3>Edit your Profile Search</h3>"; //opend database $connect = mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db("$dbname"); //select database // Get all the data from the "housing" table $result = mysql_query("SELECT * FROM users WHERE user='$user'") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) // Print out the contents of each row into a table ?> <form action="/includes/insert_profile.php" method="post"> <table border="0" cellspacing="0" cellpadding="3"> </td></tr> <tr><td>First Name:</td><td><input type="text" name="first" value="$first"> <tr><td>Middle Name:</td><td><input type="text" name="middle" value="$middle"> <tr><td>Last Name:</td><td><input type="text" name="last" value="$last"> <tr><td>Email:</td><td><input type="text" name="email" value="$email"> </td></tr> <tr><td>Date of Birth:</td><td> <select id="day" name="day" class="short"> <option value="1" selected="selected">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select id="month" name="month" class="medium"> <option value="January" selected="selected">January</option> <option value="February">February</option> </select> <select id="year" name="year" class="medium"> <option value="2010" selected="selected">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> </td></tr> <tr><td> <input type="Submit" value="Save"/> </td></tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233059-how-do-i-populate-form-value-with-mysql-data/ Share on other sites More sharing options...
spiderwell Posted April 8, 2011 Share Posted April 8, 2011 <tr><td>First Name:</td><td><input type="text" name="first" value="<?php echo $row['first'] ?>"> try replacing the table row entries with something like above where $row is your recordset and ['first'] is the appropriate column name from db Quote Link to comment https://forums.phpfreaks.com/topic/233059-how-do-i-populate-form-value-with-mysql-data/#findComment-1198620 Share on other sites More sharing options...
daverichris Posted April 8, 2011 Author Share Posted April 8, 2011 Thank you for the quick reply, but no joy, I have two pages one presents the data to the user and works fine, the second is for updating the data which is the one i want to populate so the user can see what is complete. The second is the form the doesnt work, i have included them both for you to look at. this script works perfectly <br><a href='/index.php?page=edit_profile'>edit profile</a> <?php session_start(); include 'english.php'; if (!isset($_SESSION['user'])) die("<br /><br />You need to login to view this page"); $user = $_SESSION['user']; echo "<h3>Edit your Profile Search</h3>"; //opend database $connect = mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db("$dbname"); //select database // Get all the data from the "housing" table $result = mysql_query("SELECT * FROM users WHERE user='$user'") or die(mysql_error()); echo "<table border='0' width='400px'>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo "First Name:"; echo "</td><td>"; echo $row['first']; echo "</td></tr>"; echo "<tr><td>"; echo "Middle Name:"; echo "</td><td>"; echo $row['middle']; echo "</td></tr>"; echo "<tr><td>"; echo "Last Name:"; echo "</td><td>"; echo $row['last']; echo "</td></tr>"; echo "<tr><td>"; echo "Date of Birth:"; echo "</td><td>"; echo $row['date']; echo "</td></tr>"; echo "<tr><td>"; echo "Email:"; echo "</td><td>"; echo $row['email']; echo "</td></tr>"; } echo "</table>"; ?> this form works and uploads the data to my table but wont show the data in the Value="" <?php session_start(); include 'english.php'; if (!isset($_SESSION['user'])) die("<br /><br />You need to login to view this page"); $user = $_SESSION['user']; echo "<h3>Edit your Profile Search</h3>"; //opend database $connect = mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db("$dbname"); //select database // Get all the data from the "housing" table $result = mysql_query("SELECT * FROM users WHERE user='$user'") or die(mysql_error()); // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) // Print out the contents of each row into a table ?> <form action="/includes/insert_profile.php" method="post"> <table border="0" cellspacing="0" cellpadding="3"> </td></tr> <tr><td>First Name:</td><td><input type="text" name="first" value="$first"> <tr><td>Middle Name:</td><td><input type="text" name="middle" value="$middle"> <tr><td>Last Name:</td><td><input type="text" name="last" value="$last"> <tr><td>Email:</td><td><input type="text" name="email" value="$email"> </td></tr> <tr><td>Date of Birth:</td><td> <select id="day" name="day" class="short"> <option value="1" selected="selected">1</option> <option value="2">2</option> <option value="3">3</option> </select> <select id="month" name="month" class="medium"> <option value="January" selected="selected">January</option> <option value="February">February</option> </select> <select id="year" name="year" class="medium"> <option value="2010" selected="selected">2010</option> <option value="2009">2009</option> <option value="2008">2008</option> </td></tr> <tr><td> <input type="Submit" value="Save"/> </td></tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/233059-how-do-i-populate-form-value-with-mysql-data/#findComment-1198625 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.