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
https://forums.phpfreaks.com/topic/227113-insert-into-from-loop/
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

)

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.