Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Stuck, can't explain in one sentence

    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 Code:
    <?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
    PHP Code:
    <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>
    Attached Thumbnails Attached Thumbnails Stuck, can't explain in one sentence-meals.jpg  
    Last edited by metomeya; 02-25-2010 at 02:37 AM.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    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.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    New Coder
    Join Date
    Oct 2008
    Posts
    29
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you! I think that will make things A LOT easier for me.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    mysql_query("SELECT LAST_INSERT_ID() FROM TableName");

    http://dev.mysql.com/doc/refman/5.0/...last-insert-id


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •