can't insert one form into multiple table

They have: 1 posts

Joined: Sep 2016

<?php
if(isset($_POST['submit'])){
       
       
$act_name = $_POST['act_name'];
       
$act_location = $_POST['act_location'];
       
$act_date = $_POST['act_date'];
       
$act_time = $_POST['act_time'];
       
$borrow_date = $_POST['borrow_date'];
       
$borrow_return_date = $_POST['borrow_return_date'];
                       
       
       
$insert_act = "insert into activity (act_name,act_location,act_date,act_time)
                            values ('
$act_name','$act_location','$act_date','$act_time')";
                           
       
$insert_bor = "insert into borrow_equipment (borrow_date, borrow_return_date)
                        values ('
$borrow_date','$borrow_return_date')";
       
       
$insert_reg = mysqli_query ($con, $insert_act, $insert_bor);
       
$insert_reg2 = mysqli_query ($con, $insert_bor);
       
        if(
$insert_reg2){
           
            echo
"<script>alert('Registration has been submitted')</script>";
            echo
"<script>window.open('application_form2.php','_self')</script>";
            }
            else
            {
            echo
"<script>alert('Something error with the information, Please resubmit your information')</script>";
            echo
"<script>window.open('application_form1.php','_self')</script>";
            }
           
           
        }
       
   
?>

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Since you didn't give any details, I would guess that it is the first query that is failing because you are passing a SQL statement as a 3rd parameter.

Besides this, your code is WIDE open to SQL injection, google mysqli prepared statements (or better, look into prepared statements with PDO)

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.