Jump to content

while and insert


kendris

Recommended Posts

<html>




<?php include "overallheader.php" ?>
<div id ='container'>


<div id ='content'>


<div id='navBar'>
<?php include "navbar.php"?>
</div>
<div id='userinfo'>










<?php




session_start();


if (isset($_SESSION["username"]))
{








$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("login", $con);








mysql_close($con);
}
else
die("You must be logged in <a href='index.php'>Back</a>");


 $con = mysql_connect("localhost","root","");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }
mysql_select_db("login", $con);
$result=mysql_query('SELECT eventname FROM event');
$result = mysql_query("SELECT * FROM event");
 ?>






</div>




<div id ="eventform">


  <?php




  
  $result = mysql_query("SELECT * FROM event ORDER BY `eventname` ASC");




while($row = mysql_fetch_array($result))
  {
  
  $eventid = NULL;
$iduser = NULL;
 $eventid = $row["eventid"];
  
 $result2 =  mysql_query('SELECT userid FROM users WHERE username="'.$_SESSION["username"].'"');


 while($row = mysql_fetch_array($result2))
  {


  $iduser= $row["userid"];


  }
if (isset($_GET["eventid"],$_GET["eventname"],$_GET["price"],$_GET["location"], $_GET["user"]))
{


$eventid = $_GET["eventid"];
$eventname = $_GET["eventname"];
$price = $_GET["price"];
$location = $_GET["location"];
$iduser = $_GET["user"];


}




}


{
$queryreg = mysql_query("
INSERT INTO booking VALUES ('', '$eventid', '$iduser')
");




}




echo "Your event has been booked";  
header("Refresh: 1; url=member.php");




 ?> 


</div>


</div>
</div>










</html>

I thought I had sorted this but it seems only to insert the last entry of the while loop, I'm looking for a tutorial that will help me sort the problem.  It should insert each selected row. 

Link to comment
https://forums.phpfreaks.com/topic/277144-while-and-insert/
Share on other sites

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.