Jump to content

how do I populate form Value="" with mysql data


daverichris

Recommended Posts

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>

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.