Jump to content

any experts out there?


dosser

Recommended Posts

Hi guys sure you can help me with this one, sorry for the long post just want to give as much info as poss.

I have database set up in mysql and an html form set up to enter data into it. works fine and dandy. however I now have to go one step further and got stuck.

The database is called food. Four tables are:

recipe - recipe_id (primary key, auto-incr), and recipe_name
chef - chef_id (pr.key, auto-incr) and chef_name
restaurant - restaurant_id (pr.key, auto-incr) and restaurant_name
meal - meal_id (pr.key, auto-incr), meal_info, recipe_id, creator_id, restaurant_id.

Meal=the reason you were at the restaurant (eg Son's Birthday, Marriage etc)

The code for the html form is as follows:


<html><body>

<form action="process.php" method="post">
Recipe: <input type=text name="recipe" size=40><br/><br/>
Chef: <input type="text" name="chef1" size=40><br/><br/>
Restaurant: <input type="text" name="restaurant1" size=40><br/><br/>
Meal: <input type=text name="meal1" size=140><br /><br/>

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
<input type=reset name"reset" value="reset">

</form>
</body></html>

This then goes to a to the process.php as follows.

<?php

$conn=mysql_connect("localhost","******","******");
if (!$conn)
{die('Could not connect to mysql');}

$db= mysql_select_db("food",$conn);
$recipe_name=mysql_query("insert into recipe values('null','$_POST[recipe]')");
$recipe_id=mysql_insert_id();
$chef_name=mysql_query("insert into chef values('null','$_POST[chef1]')");
$chef_id=mysql_insert_id();
$restaurant_name=mysql_query("insert into restaurant values('null','$_POST[restaurant1]','null','null')");
$restaurant_id=mysql_insert_id();
$meal_info=mysql_query("insert into meal values('null',$recipe_id,$creator_id,'$_POST[meal1]',$restaurant_id)");

if (!$recipe)
{die('Error with recipe');} echo"Recipe Success!";
if (!$chef1)
{die('Error with artist');} echo"Chef Success!";
if (!$restaurant1)
{die('Error with restaurant');} echo"Restaurant Success!";
if (!$ingredient1)
{die('Error with meal');} echo"Meal Success!";


?>

Obviously this is all just to test it was working so not worried about the output just yet. However, I now realise that this will only work for one set of chef/restaurant/meal - hence why I put eg 'chef1' rather than chef..

So the problem is that this works fine for one set of data, but I want to have the html form set out to accept more than one chef/restaurant/meal eg:

<form action="process.php" method="post">
Recipe: <input type=text name="recipe" size=40><br/><br/>
Creator: <input type="text" name="creator1" size=40><br/><br/>
Restaurant: <input type="text" name="restaurant1" size=40><br/><br/>
Meal: <input type=text name="meal1" size=140><br /><br/>

Creator: <input type="text" name="creator2" size=40><br/><br/>
Restaurant: <input type="text" name="restaurant2" size=40><br/><br/>
Meal: <input type=text name="meal2" size=140><br /><br/>

Creator: <input type="text" name="creator2" size=40><br/><br/>
Restaurant: <input type="text" name="restaurant2" size=40><br/><br/>
Meal: <input type=text name="meal2" size=140><br /><br/>

Creator: <input type="text" name="creator2" size=40><br/><br/>
Restaurant: <input type="text" name="restaurant2" size=40><br/><br/>
Meal: <input type=text name="meal2" size=140><br /><br/>

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!">
<input type=reset name"reset" value="reset">

</form>

The idea is, you could have eaten eg lasagna at many different restaurants by different chefs at different times, or the same chef at different restaurants etc etc. The recipe will be the same for all the

So what I think I need is something like a PHP loop which encorporates the mysql INSERT command I have in process.php. But how do I then name the parts of the form? eg 'chef2', 'restaurant2', 'meal2'?

Do i use while... or for ($i++) and if so what how does that fit into the rest of the process.php?

Any ideas ?

Thanks in advance

D

sorry one error - the line

"insert into meal values('null',$recipe_id,$creator_id,'$_POST[meal1]',$restaurant_id)"

it should read $chef_id not $creator_id
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.