...

View Full Version : Stuck, can't explain in one sentence



metomeya
02-25-2010, 02:25 AM
My brain just can' take any more

I have a page that posts to its self. It was partly working...but suddenly it stopped.

You should input the meal name, ingredient amounts, and meal type (breakfast, dinner, etc.) and click the OK button.

This will put the meal name and meal type into the database and re-load the page with the amount of ingredients to put in (not finished programming that yet) and the description

The problem Im having is carrying over the mealname and ID to link it to the ingredients and direction re-enter in the same page with the submit button.


I know its not the most effective/efficient way of doing it (i'm not a programm), but i'm just trying to get it to work.

Here is the code and a view of the website...thanks for any suggestions



<?php include("code/header.html"); ?>
<?php include("code/connect.php"); ?>
<?php include("code/links.html"); ?>

<?php
/////////////////Select Data/////////////////
include 'baaSelect.php';
$sel = new baaSelect();

$sel->addSelect('mealtype', 'mealtypes', 'typeID', 'typeName','',1,'--Select--');
$sel->addSelect('meal', 'meals', 'MealID', 'mealName','typeID',1,'----------Select----------');

$sel->makeScript();
//////////////////////////////////////////////

/////////////////Meal Type////////////////////
$sql_options="SELECT typeID, typeName FROM mealtypes ORDER BY typeID";
$result_options=mysql_query($sql_options);

$type_options="";

while ($row=mysql_fetch_array($result_options))
{
$typeid=$row["typeID"];
$typename=$row["typeName"];
$type_options.="<OPTION VALUE=\"$typeid\">".$typename;
}
//////////////////////////////////////////////

////////Insert Recipe Name, Meal Type/////////
if (isset($_POST[recipe_name]) && isset($_POST[add_type]))
{
$SQL5 = "INSERT INTO meals(mealName, typeID)
VALUES ('$_POST[recipe_name]', '$_POST[add_type]')";
if (!mysql_query($SQL5, $con))
{ die('Error: ' . mysql_error()); }
echo "1 unit added";


//$SQL78 = mysql_fetch_array($SQL77);
//$SQL99 = $SQL78['mealID'];

$SQL77 = mysql_query("SELECT * FROM meals WHERE mealName='$_POST[recipe_name]'");
while($row = mysql_fetch_array($SQL77))
{
echo $row['mealID'] ;
echo "<br />";
}

}

/////////////Insert Description////////////////
if (isset($_POST[recipe_name2]))
{
$SQL10 = "UPDATE meals SET RecDesc = '$_POST[desc2]' WHERE mealName = '$_POST[recipe_name2]'";

if (!mysql_query($SQL10, $con))
{ die('Error: ' . mysql_error());}
echo "1 description added";
}
echo $SQL99;

?>


<center>
<table border="0">
<tr>
<td>
<?php include("recipe_table1.php"); ?>
</td>

<td>
<?php include("recipe_table2.php"); ?>
</td>
<tr>
</table>
</center>

<?php include("code/footer.php"); ?>


recipe_table1.php


<table frame="border" border="1">
<tr>
<td colspan="4">
<form action="recipe.php" method="post">
Recipe Name: <br> <input type="text" name="recipe_name" size="80" />
</td>
</tr>

<tr>
<td>
# of Ingredients: <br> <input type="text" name="amount_ingred" size="1"/>
</td>

<td colspan="2">
Meal Type:
<br>
<select name="add_type">
<option><?php echo $type_options?></option>
</select>
</td>

<td>
Input:
<br>
<input type="submit" value="Confirm" />
</form>
</td>
</tr>

<tr>
<td colspan="4">
<form action="recipe.php" method="post">
Recipe Name: <br> <input name="recipe_name2" type="text" value="<?php echo $SQL100 ?>" size="80" />
</td>
</tr>

<tr>
<td> Amt: </td>
<td> Unit: </td>
<td> Ingredient: </td>
<td><?php echo $SQL99; ?></td>
</tr>

<?php
if (isset($_POST[amount_ingred]))
{
//$result = mysql_query("SELECT * FROM recipeingredients WHERE MealID = '$_POST[meal]'");
for ($i=1; $i<=$_POST[amount_ingred]; $i++)
{
echo "<tr>";
echo "<td> <input type='text' name=" . NULL . " size=1 /></td>";
echo "<td><select><option>example</option></select> </td>";
echo "<td><select><option>description of the ingredients</option></select> </td>";
echo "</tr>";
}
}
?>

<tr>
<td colspan="4">
Directions: <br> <textarea name="desc2" cols="60" rows="10"> <?php echo $_POST[add_type]; echo $SQL77; ?></textarea>
</td>
</tr>

<tr>
<td colspan="3">
</td>
<td>
<input type="submit" value="Add" />
</form>
</td>
</tr>
</table>


http://www.codingforums.com/attachment.php?attachmentid=8263&stc=1&d=1267064717

masterofollies
02-25-2010, 04:27 AM
If you're using an auto increment for ID, you can pull the last query information. I forgot the name of the query code for it, hopefully someone will reply and remembers it. It pulls the last submitted query and you can extract your data from that.

metomeya
02-25-2010, 02:40 PM
Thank you! I think that will make things A LOT easier for me.

Nightfire
02-25-2010, 09:07 PM
mysql_query("SELECT LAST_INSERT_ID() FROM TableName");

http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_last-insert-id



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum