www.webdeveloper.com
Results 1 to 5 of 5

Thread: Sending HTML Form Data to 2 SQL tables

  1. #1
    Join Date
    Feb 2011
    Posts
    13

    Sending HTML Form Data to 2 SQL tables

    Hello,

    I'm trying to send some form data to two SQL tables. Below is the code I have. When I use the code below, it's showing that the information was successfully added. I go to the database and it adds the info to the restaurant table, but the "food" info is not added to the food type table.

    Also, one final thing. 'Restaurant' is a foreign key in the food type table. How do I note that in the code below?
    PHP Code:
    <?php require_once("db_connx.php");
    $restaurant $_POST['restaurant'];
    $address $_POST['address'];
    $city =  $_POST['city'];
    $state $_POST['state'];
    $zip $_POST['zip'];
    $phone $_POST['phone'];
    $type $_POST['type'];
    $cost $_POST['cost'];
    $food $_POST['food'];

    if (
    mysql_query ("INSERT INTO restaurant (Restaurant, Address, City, State, Zip, Phone, Type, AverageCost) VALUES ('$restaurant', '$address', '$city','$state', '$zip', '$phone', '$type', '$cost')INSERT INTO food type(Food Type) VALUES('$food')"))
    { echo 
    "Restaurant successfully added to the database <br />"
     }
    else
    { echo 
    "Error adding restaurant"; }
    require_once(
    "db_connx_close.php");
    ?>

  2. #2
    Join Date
    Mar 2012
    Posts
    63
    Make it as two separate query and execution

  3. #3
    Join Date
    May 2012
    Posts
    17
    As stated above you're better off turning this into two separate queries, however I expect the error is the space between Food Type in the second sql query.

    PHP Code:
    INSERT INTO food type(`Food Type`) VALUES('$food'); 
    you need the backticks.

  4. #4
    Join Date
    May 2012
    Posts
    1
    Thank you

  5. #5
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Can you have a table name with spaces in it?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles