proud Posted April 15, 2007 Share Posted April 15, 2007 I'm trying to insert multiple records from a form here is my form page: <form name="video" action="http://localhost/video_exec.php" method="post"> Video Src 1 : <input name="src1" size="20" ><br> Title 1:<input name="title1" size="20"><br> Speaker 1 : <input name="spkr1" size="20"> <br><br> Video Src 2 : <input name="src2" size="20" ><br> Title 2:<input name="title2" size="20" ><br> Speaker 2: <input name="spkr2" size="20"> </form> here is the page in which the data is posted and then inserted into the database: <?php include( 'connect.php' ); $a=$_POST['src1']; $b=$_POST['title1']; $c=$_POST['spkr1']; $d=$_POST['src2']; $e=$_POST['title2']; $f=$_POST['spkr2']; $sql = "INSERT INTO video_sem (src,name,spkr) VALUES ('$a','$b','$c'), ('$d','$e','$f')"; mysql_query( $sql); ?> Although this query worked with me when i tried it with forms i dont know what went wrong. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 15, 2007 Share Posted April 15, 2007 Why don't you just make another INSERT query? ...I have never seen a query done like that before... Quote Link to comment Share on other sites More sharing options...
proud Posted April 15, 2007 Author Share Posted April 15, 2007 $sql = "INSERT INTO video_sem (id,src,name,spkr) VALUES ( ' ' , ' $a ' , ' $b ' , ' $c ')"; $sql2 = "INSERT INTO video_sem (id,src,name,spkr) VALUES ( ' ' , ' $d ' , ' $e ' , ' $f ')"; $result=mysql_query($sql); $result2=mysql_query($sql2); Do you mean multiple queries like this one above? I've tried this one and the result of the insertion in the database is like this: id src title spkr 30 Array Array Array Quote Link to comment Share on other sites More sharing options...
HoTDaWg Posted April 15, 2007 Share Posted April 15, 2007 although i dont get what you are doing (but dats cuzza my noobishness), its a good habbit to include your connection when executing a query. <?php $result2 = mysql_query($sql2,$connection); ?> also...at the risk of insulting you (which is completely unintentional)...why dont you just make ur script: <?php include( 'connect.php' ); $a=$_POST['src1']; $b=$_POST['title1']; $c=$_POST['spkr1']; $d=$_POST['src2']; $e=$_POST['title2']; $f=$_POST['spkr2']; $sql = "INSERT INTO video_sem (src,name,spkr) VALUES ('$a','$b','$c','$d','$e','$f')"; $results = mysql_query($sql,$connection); ?> I am curious to know why are you making two seperate insert into commands? Having two seperate forms does not necessairily mean you need two seperate insert commands... HoTDaWg Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 15, 2007 Share Posted April 15, 2007 HoTDaWg - How can he add 6 values into the database in the query when he has only defined 3 column names? Maybe I am just retarded...not sure, haha =] Quote Link to comment Share on other sites More sharing options...
suttercain Posted April 15, 2007 Share Posted April 15, 2007 How can he add 6 values into the database in the query when he has only defined 3 column names? You can't. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted April 15, 2007 Share Posted April 15, 2007 Ah, I didn't think so. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.