Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to Insert values on Multiple Table on my data base

I need to insert values into multiple table. Please correct my code because it just double the inserted value on table_attendace

if(isset($_POST['text']))
    {

        $text =$_POST['text'];


        // insert query 
        $sql = "INSERT INTO table_attendance(NAME,TIMEIN) VALUES('$text',NOW())";
        $query =mysqli_query($conn,$sql) or die(mysqli_error($conn));
        
        if($query==1) 
        {
            $ins="INSERT INTO table_attendancebackup(NAME,TIMEIN) VALUES('$text',NOW())";
            $quey=mysqli_query($conn,$sql) or die(mysqli_error($conn));
                if ($quey==1) {
                    $_SESSION['success'] = 'Action Done';
                }else{
                    $_SESSION['error'] = $conn->error;
                }
        }
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

In the second query, you reused the first query $sql again, instead of using $ins.
It should be

$quey=mysqli_query($conn,$ins) or die(mysqli_error($conn));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading