Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4115222
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:33:15+00:00 2026-05-20T22:33:15+00:00

i have been recently studying php and mysql and also is currently developing a

  • 0

i have been recently studying php and mysql and also is currently developing a online web form using php and mysql. in the form i have multiple tables that i need to submit data to. i have tried this code;

 $required_fields = array('event_type','accommodation_type','public_user','comments','grand_total');
    $required_fields2 = array('first_name','last_name','gender','age_group');
    $errors = array_merge($errors, check_required_fields($required_fields, $_POST));
    $errors2 = array_merge($errors2, check_required_fields($required_fields2, $_POST));

    $fields_with_lengths = array('event_type' => 50, 'accommodation_type' => 50, 'public_user' => 50,'comments' => 10000,'grand_total' => 50);
    $fields_with_lengths2 = array('first_name' => 50, 'last_name' => 50, 'gender' => 50,'age_group' => 50);
    $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
    $errors2 = array_merge($errors2, check_max_field_lengths($fields_with_lengths2, $_POST));

    $event_type = trim(mysql_prep($_POST['event_type']));
    $accommodation_type= trim(mysql_prep($_POST['accommodation_type']));
    $public_user = trim(mysql_prep($_POST['public_user']));
    $comments = trim(mysql_prep($_POST['comments']));
    $grand_total = trim(mysql_prep($_POST['grand_total']));

    if (empty($errors)){
        $query = "INSERT INTO event_registration (event_type, accommodation_type, public_user, comments, grand_total) VALUES ('{$event_type}','{$accommodation_type}','{$public_user}','{$comments}','{$grand_total}')";
        $result = mysql_query($query, $connection);

        if($result){
            $message = "The User was successfully registered";
        } else{
            $message = "The User could not be registered";
            $message .= "<br />" . mysql_error();
        }
    } else{

        if(count($errors)==1){
            $message = "There was 1 error in the form.";
        } else {
            $message = "There were" . count($errors) . " error in the form.";
        }   
    }

} else { // Form has not been submitted
    $event_type = "";
    $accommodation_type = "";
    $public_user = "";
    $comments = "";
    $grand_total = "";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:33:16+00:00Added an answer on May 20, 2026 at 10:33 pm

    In general, here’s how you post data from one form into two tables:

    <?php
    $dbhost="server_name";
    $dbuser="database_user_name";
    $dbpass="database_password";
    $dbname="database_name";
    
    $con=mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to the database:' . mysql_error());
    
    $mysql_select_db($dbname, $con);
    
    $sql="INSERT INTO table1 (table1id, columnA, columnB) 
             VALUES (' ', '$_POST[columnA value]','$_POST[columnB value]')";
    
    mysql_query($sql);
    
    $lastid=mysql_insert_id();
    
    $sql2="INSERT INTO table2 (table1id, table2id, columnA, columnB)
                  VALUES ($lastid, ' ', '$_POST[columnA value]','$_POST[columnB value]')";
    
    //table1id & table1id are auto-incrementing primary keys 
    
    mysql_query($sql2);
    
    mysql_close($con);
    
    ?>
    

    This example shows how to insert data from a form into multiples tables, I have not shown any security measures.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been using rails for a web application, and so I have
Recently I have been studying recursion; how to write it, analyze it, etc. I
I have recently been working with Python using Komodo Edit and other simpler editors
I have recently been web-researching quantum computing. Will we see these in our lifetimes
I have recently been studying UML and drawing simple diagrams with ordinary plain arrows
I've recently been studying TDD, attended a conference and have dabbled in few tests
I've been studying Python 3 recently and I have come across a conundrum: I
I've been studying Haskell in my spare time and have recently crossed into the
I have recently been developing a website for a company, with a full administration
I have recently been using cookie store and I want to transition to active

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.