MDGM 22 Posting Whiz in Training

surely just saving the login timestamp updating it every time the page is refreshed and then querying for users where the timestamp is less than x minutes ago are online would be the best answer?

MDGM 22 Posting Whiz in Training

yes post code please.

without seeing the code i think you have two options:

If you have access to the first action page (before paypal) then add this at the very end of the script (before any actual text output):

<?php
header('location: http://www.secondFormAction.com');
exit;
?>

which will forward the user to the next form action. if you do not have access to the first action then consider using ajax to submit the second action?

MDGM 22 Posting Whiz in Training

Sure,

$sql="INSERT INTO bookings 
(clientID, roomID, startdate, enddate, adults, children, roomtype,  requirements) 
VALUES 
('$last_insert_client_id',
'NULL',
'  str_to_date($_POST[startdate],'%d-%m-%Y')',
'  str_to_date($_POST[enddate],'%d-%m-%Y')',
'$_POST[adults]',
'$_POST[children]',
'$_POST[roomtype]', 
'$_POST[requirements]')
";

That should give you what you want.

MDGM 22 Posting Whiz in Training

I think generally to store dates into the database its best to use a timestamp. A timestamp shows the number of seconds that have passed since January 1, 1970 00:00:00 GMT. You get the current timestamp in php by using: time(); //http://uk.php.net/manual/en/function.time.php You can convert a date into a timestamp using the following: mktime('','','',$month,$day,$year); //http://uk.php.net/manual/en/function.mktime.php And you can convert timestamp into a date by using this: date('D-M-Y',$timestamp); Using these functions, get the user to enter in their date in the format you want (DD/MM/YY) using 3 different text boxes like this:

<form action="process.php" method="post">
<input type="text" name="day" value="day"/><br />
<input type="text" name="month" value="month"/><br />
<input type="text" name="year" value="year"/><br />
<input type="submit" /><br />
</form>

then on the next page process it like this:

<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];

$timestamp = mktime('','','',$month,$day,$year);

//then store the timestamp into the database 
?>

Then later if you want to get the timestamp from the database do something like this:

<?php
$get_date = mysql_query('SELECT timestamp FROM table WHERE bookingID = "'.$bookingID.'"');
$timestamp = mysql_fetch_array($get_date);
$timestamp = $date['timestamp'];

$timestamp = date('D-M-Y',$timestamp);
//$timestamp is now a readable version of the timestamp date in the database
?>

the good thing about using timestamps is that if you want to order the items in your database by date you can do it easily. Also if you want to get bookings within the last month, do something like this:

$now = time();
$oneMonthInSeconds = 2629743;
$lastmonth = …
MDGM 22 Posting Whiz in Training

Ahhh i know whats going wrong. This bit:

foreach($result_array as $key => $value)
{
echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>';
echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>';
echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>';
echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>';
echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>';
echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>';
}
echo '</table>';

is saying that for every piece of information saved inside the results array, write a table with the results. Take that out of the foreach function and have it on its own. Here how the whole code should look:

<?php

// open database connection code and then my code as follows

$sql="UPDATE bookings SET startdate ='$_POST[startdate]',enddate='$_POST[enddate]',adults='$_POST[adults]',children='$_POST[children]',roomtype='$_POST[roomtype]', requirements='$_POST[requirements]'
WHERE bookingID = '$_POST[bookingID]'";
 
if (!mysql_query($sql,$con))
  {
  die('Error:  ' . mysql_error());
  } 

  print "Your booking ID ".$bookingID;
  
  echo "    has been changed";


$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'");


$result_array = mysql_fetch_array($result);

echo '<table border=1>';
echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>';
echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>';
echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>';
echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>';
echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>';
echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>';
echo '</table>';


mysql_close($con);
?>

The query returned 9 pieces of information and stored them inside an array. Then the foreach function was going through all nine items in the array and printing your table of results

MDGM 22 Posting Whiz in Training

Thats really wierd..

Can you send the entire code to me?

MDGM 22 Posting Whiz in Training

try using this:

$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$_POST['bookingID']."'");

sometimes when you don't encapsulate the second part of the where condition in speech marks it treats it like a search term when your saying "select * from bookings where bookingID like '%term%'

MDGM 22 Posting Whiz in Training

Ah okay I understand.

the only possible reason for this, is that in your database, you are searching for all records where the bookingID is 33. You must have 9 different records that fit this description.

You have 2 options here:
- Add "LIMIT 1" to the end of your query, however this will limit the result to one row, but might get the wrong one...
- Change the bookingID column in your table to an auto increment primary key (http://grafax.co.uk/OTHER/max/daniweb/primarykey_AI-autoincrement.bmp)

It would also help if you sent me your whole code now too, and mayeb a screenshot of your database setup.

Max

MDGM 22 Posting Whiz in Training
<?php

//do your query
$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$last_insert_booking_id."'");

//because your query uses a primary key, we only have one result and so don't have to use the while function. instead, save all the query results into an array.
$result_array = mysql_fetch_array($result);

echo '<table>';
//for each piece of information saved in the array, display it to the user.
foreach($result_array as $key => $value)
{
	echo '<tr><td>Start Date</td><td>'.$result_array['startdate'].'</td></tr>';
	echo '<tr><td>End Date</td><td>'.$result_array['enddate'].'</td></tr>';
	echo '<tr><td>Adults</td><td>'.$result_array['adults'].'</td></tr>';
	echo '<tr><td>Children</td><td>'.$result_array['children'].'</td></tr>';
	echo '<tr><td>Roomtype</td><td>'.$result_array['roomtype'].'</td></tr>';
	echo '<tr><td>Requirements</td><td>'.$result_array['requirements'].'</td></tr>';
}
echo '</table>';

?>

what do you mean:
BTW is it possible for my to write the row titles rather than retrieving them from the table.


Max

MDGM 22 Posting Whiz in Training

What do you mean by:
2) It does bring back everything from the table

As for bringing it back in a table, use this:

<?php

//do your query
$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$last_insert_booking_id."'");

//because your query uses a primary key, we only have one result and so don't have to use the while function. instead, save all the query results into an array.
$result_array = mysql_fetch_array($result);

//setup your table
echo '<table>';

//for each piece of information saved in the array, display it to the user.
foreach($result_array as $key => $value)
{
	if( !is_int($key) )
	{
		echo '<tr><td>';
		echo $key;
		echo '</td><td>';
		echo $value;
		echo '</td></tr>';
	}
}

//cloes your table
echo '</table>';
MDGM 22 Posting Whiz in Training

yeah sure. assuming you understand arrays, the foreach function cycles through each array segment and runs a specific piece of code for that segment. The segment's title is saved in the $key variable, and it's contents is saved in the $value variable.

So from your mysql query, the $result_array would be filled with each columns value. The $key will be the column name, and the value of it will be the value of that column in the query.

So doing this:

echo $result_array;

would write that user's booking id.

doing this:

echo $result_array;

would write that users first name (providing that information was saved in the database of course...)

Hope that helps. Max

MDGM 22 Posting Whiz in Training

try this:

<?php

//do your query
$result = mysql_query("SELECT * FROM bookings WHERE bookingID='".$last_insert_booking_id."'");

//because your query uses a primary key, we only have one result and so don't have to use the while function. instead, save all the query results into an array.
$result_array = mysql_fetch_array($result);

//for each piece of information saved in the array, display it to the user.
foreach($result_array as $key => $value)
{
	if( !is_int($key) )
	{
		echo $key.' | '.$value.'<br />';
	}
}

?>

That will write all the results nicely to the page with titles for the user. You can organise it nicely into tables by changing the code echo'd in the foreach section if you want.

Max