Page 1 of 1

Only echoes the second time around .... ?

Posted: Sun Mar 21, 2004 11:44 pm
by Steveo31
Hey all.

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();
		
?>

Posted: Mon Mar 22, 2004 7:52 am
by coreycollins
It looks like you run the insert after you do the SELECT. Shouldn't the Select mysql_query be after your insert user info mysql_query.

Posted: Mon Mar 22, 2004 11:33 am
by Illusionist
yeah its becase you querying the SELECT statement from the DB before you INSERT into it....

Posted: Mon Mar 22, 2004 1:50 pm
by Steveo31
Ahh okay. Thanks.

:)