This code here works okay, just has to be refreshed to get it to echo the correct values. Does anyone know why? I'm thinking its the auto_increment, but I'm not sure.
Code: Select all
<?php
$db = mysql_connect("localhost", "root") or die("Error. ".mysql_error());
mysql_select_db('vacation', $db) or die(mysql_error());
$name = $_POST['name'];
@$jamaica = $_POST['jamaica'];
@$bolivia = $_POST['bolivia'];
@$haiti = $_POST['haiti'];
if($jamaica){
$location = 'jamaica';
}elseif($bolivia){
$location = 'bolivia';
}elseif($haiti){
$location = 'haiti';
}
$userInfo = "INSERT INTO ".$location." (`name`) VALUES ('".$name."')";
$tripInfo = "SELECT name, total FROM `".$location."`";
$getTotal = "SELECT COUNT(total) FROM `".$location."`";
$getTripInfo = mysql_query($tripInfo, $db) or die("getTripInfo ".mysql_error());
$totalResult = mysql_query($getTotal, $db);
$row = mysql_fetch_row($totalResult);
//
//it should output all of this here, and does once refreshed... but I shouldn't have to refresh...
//
$insertUserInfo = mysql_query($userInfo, $db) or die("InsertUserInfo: ".mysql_error());
while($row = mysql_fetch_assoc($getTripInfo)){
echo "You chose to go on the <b>".$location."</b> Trip.<br>";
echo "Name: ".$row['name']."<br>";
echo "Your Spot Number: ".$row['total'];
}
mysql_close();
?>