...

View Full Version : Fetch mysql data and insert into a form



coatse
08-17-2012, 06:23 AM
Hi, I have a form that i want to be able to reload mysql data into it and a user can click the next or previous button to scroll through the data and update it

my form is

<form action="addrest1.php" method="POST">
<table width="264" border="0" cellspacing="2">
<tr>
<td width="180">&nbsp;</td>
<td width="10">&nbsp;</td>
<td width="62">&nbsp;</td>
</tr>
<tr>
<td><label>Resturant Name: </label>&nbsp;
<label for="name"></label>
<input type="text" value="" name="name" id="name"></td>
<td>&nbsp;</td>
<td><input type="submit" name="first5" id="first5" value="ADD"></td>
</tr>
<tr>
<td>Location:
<input type="text" name="location" id="location"></td>
<td>&nbsp;</td>
<td><input type="button" name="first6" id="first6" value="UPDATE"></td>
</tr>
<tr>
<td>Address:
<input type="text" name="address" id="address"></td>
<td>&nbsp;</td>
<td><input type="button" name="first7" id="first7" value="DELETE"></td>
</tr>
<tr>
<td>Email:
<input type="text" name="email" id="email"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Telephone:
<input type="text" name="telephone" id="telephone"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><p>Cuisine Type:
<?php
mysql_connect("localhost", "root", "coatez") or die(mysql_error());
mysql_select_db("restaurant") or die(mysql_error());
$query="SELECT type FROM cuisine_type";
$result = mysql_query($query);

echo '<select name="cuisine_id" id="cuisine_id">';
while($nt=mysql_fetch_array($result)){ //Array or records stored in $nt
echo '<option name="select" value="' . $nt['type'] . '">' . $nt['type'] . '</option>';
/* Option values are added by looping through the array */
}
echo '</select>'; // Closing of list box
?>

</p>
<p><a href="cuisineform.php" target="frame"><input type="button" value="Add new Type"/></a><A HREF="javascript:history.go(0)"><input type="button" value="Refresh List"/></A></p>
<p>
<label for="cuisine_id"></label>
</p>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Signature Dish:
<input type="text" name="signature_dish" id="signature_dish"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Price Range:
<input type="text" name="price_range" id="price_range"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>Payment Type:
<input type="text" name="payment_type" id="payment_type"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td><input type="button" name="first" id="first" value="Prev">
<input type="button" name="first2" id="first2" value="Next"></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
</form>

Thanks
James

:thumbsup::)

MarkR
08-17-2012, 02:09 PM
Where are you struggling?

Also using session data with the global array $_SESSION might be a better way to go. It'll be easier and you don't have to worry about database connections until you finally store it.

coatse
08-18-2012, 04:20 AM
Where are you struggling?

Also using session data with the global array $_SESSION might be a better way to go. It'll be easier and you don't have to worry about database connections until you finally store it.

I am struggling to make the form fetch the data back from the MySQL table, and when the user clicks the < > buttons it will change the data in the form fields and then they can simply update them.

I will be similar to how ms access does it to add a new record or update a present record

can you direct me to some tutorials on how to do a global array for $_SESSION
Thanks

James



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum