Jump to content

Problem with Inserting multiple rows posted from a form


proud

Recommended Posts

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.

Link to comment
Share on other sites

$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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.