HI
i have this script that insert values to 2 tables ..
when i use only 2 insert it works but more than 2 does not
please find my code

<?php
error_reporting(E_ALL);
$db=mysql_pconnect("localhost:3306","root","root");
mysql_select_db("campion",$db);
$d='DELETE FROM net';
$m=mysql_query($d);
$d1='DELETE FROM net_lib';
$m1=mysql_query($d1);
$q2="SELECT serial_no,UnitName,pulser1_name,pulser2_name,pulser3_name,pulser4_name,pulser1_input_type,
    pulser2_input_type,pulser3_input_type,pulser4_input_type FROM net_watch_units";
                   $res2=mysql_query($q2);
while($r2 = mysql_fetch_array($res2)) {                   

                   $serial=$r2['serial_no'];
                   $unit=$r2['UnitName'];
                   $p1=$r2['pulser1_name'];
                   $p2=$r2['pulser2_name'];
                   $p3=$r2['pulser3_name'];
                   $p4=$r2['pulser4_name']; 
                   $t1=$r2['pulser1_input_type'];
                   $t2=$r2['pulser2_input_type'];
                   $t3=$r2['pulser3_input_type'];
                   $t4=$r2['pulser4_input_type']; 



                   $sql="INSERT INTO net (serial_no,unitname)
                   VALUES
                   ($serial,'$unit')";
                    $res=mysql_query($sql,$db);
                    $sql1="INSERT INTO net_lib (serial_no,pulser_name,input_type)
                    VALUES
                    ($serial,'$p1',$t1)";
                   $res1=mysql_query($sql1,$db);
                   $sql2="INSERT INTO net_lib (serial_no,pulser_name,input_type)
                   VALUES
                   ($serial,'$p2',$t2)";
                   $res2=mysql_query($sql2,$db);
                   $sql3="INSERT INTO net_lib (serial_no,pulser_name,input_type)
                   VALUES
                   ($serial,'$p3',$t3)";
                   $res3=mysql_query($sql3,$db);
                   $sql4="INSERT INTO net_lib (serial_no,pulser_name,input_type)
                   VALUES
                   ($serial,'$p4',$t4)";
                   $res4=mysql_query($sql4,$db);
}

?> 

Display the queries and check them in phpmyadmin (and post here if you do not find an error). Insert this code after line 46 but before the closing curly bracket:

echo "SQL: $sql<br>SQL1: $sql1<br>SQL2: $sql2<br>SQL3: $sql3<br>SQL4: $sql4";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.