Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-17-2012, 05:23 AM   PM User | #1
coatse
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
coatse is an unknown quantity at this point
Smile Fetch mysql data and insert into a form

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

coatse is offline   Reply With Quote
Old 08-17-2012, 01:09 PM   PM User | #2
MarkR
New Coder

 
Join Date: Sep 2011
Posts: 80
Thanks: 0
Thanked 13 Times in 12 Posts
MarkR is an unknown quantity at this point
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.
__________________
Web Design Newcastle
MarkR is offline   Reply With Quote
Old 08-18-2012, 03:20 AM   PM User | #3
coatse
New to the CF scene

 
Join Date: Aug 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
coatse is an unknown quantity at this point
Smile

Quote:
Originally Posted by MarkR View Post
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
coatse is offline   Reply With Quote
Reply

Bookmarks

Tags
form, input, mysql, reload

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:41 AM.


Advertisement
Log in to turn off these ads.