Jump to content

INSERT INTO from loop


tjverge

Recommended Posts

I have a code that will enter the information into a database but as follows:

 

A B C D E

1

2

3

4

5

 

I am looking for it all to be on the same row like:

A B C D E

1 2 3 4 5

 

Here is my code:

<?php
if($_SESSION['admin'] !='Yes')
{
Echo "You are not approved to view this page!";
}
Else
{

echo "<form action=main.php?id=test1.php method=post>";
echo "<table border=0>";
$sql = "select * from `pipilots` WHERE `enabled` = 'Yes' ORDER BY `pilot name` ASC";
$result = mysql_query($sql) or die (mysql_error());

?>
<td>Date</td>
    <td><input name="pi" id="pi" type="hidden" size="10">
  <a href="javascript:NewCal('pi','YYYYMMDD')"><img src="images/cal.gif" width="16" height="16" border="0" alt="Pick a date"></a></td>
<?php
echo "<tr><td>Pilot Name: </td><td><select name = pilotname>";
while ($row = mysql_fetch_array($result)) {
echo "<option Value=".rawurlencode($row['pilot name']).">".$row['pilot name']."</option>";
}
echo "</select></td></tr>";


$sql = "select * from `piprice` WHERE `enabled` = 'Yes' ORDER BY `product name` ASC";
$result = mysql_query($sql) or die (mysql_error());
$count = mysql_num_rows($result);
while ($row = mysql_fetch_array($result)) {
$pname[] = $row['product name'];
echo "<tr><td>".$row['product name'].":</td><td> <input name=name[] type=text></td></tr>";
}

echo"</table>
<input name=submit type=submit Value=Add>
</form>";

if(isset($_POST['submit']))
{
$name = $_POST['name'];
$date = $_POST['pi'];
$pilotname = $_POST['pilotname'];
echo rawurldecode($pilotname)."<br>";
echo $date."<br>";
for($i=0;$i<$count;$i++){
echo $pname[$i]." = ".$name[$i]."<br>";
$sql1="INSERT INTO `pi` (`pilot name`, `$pname[$i]`, `date`) VALUES ('$pilotname', '$name[$i]', '$date' )";
$result1=mysql_query($sql1) or die (mysql_error());
}
}}
?>

 

And this is the part that I think I need help with:

if(isset($_POST['submit']))
{
$name = $_POST['name'];
$date = $_POST['pi'];
$pilotname = $_POST['pilotname'];
echo rawurldecode($pilotname)."<br>";
echo $date."<br>";
for($i=0;$i<$count;$i++){
echo $pname[$i]." = ".$name[$i]."<br>";
$sql1="INSERT INTO `pi` (`pilot name`, `$pname[$i]`, `date`) VALUES ('$pilotname', '$name[$i]', '$date' )";
$result1=mysql_query($sql1) or die (mysql_error());
}

 

Any help would be great.

Link to comment
Share on other sites

Array

(

    [pi] => 2011-2-8

    [pilotname] => TX

    [name] => Array

        (

            [0] => 1

            [1] => 2

            [2] => 3

            [3] => 4

            [4] => 5

            [5] => 6

            [6] => 7

            [7] => 8

            [8] => 9

            [9] => 10

        )

 

    [submit] => Add

)

 

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.