murphyz
01-07-2004, 10:36 PM
Quite hard to explain, so shall try and if I make no sense, please ask.
Page is displayed taking info from a database depending on a particular field (user_riddle) of the user. Page also has a form at the end.
User enters details to the form and submits - which reloads the page.
If the data is false. the page reloads as before - no problem here.
If the data is true, user_riddle increments by 1, which should result in a different set of info coming out of the database.
However, the script runs as before, and I need to manually refresh the page for the database to be queried again to get the new info. I would like to reload the page after the user_riddle has incremented...how can I do this?
<?php
// Request the user_riddle number
global $userdata;
echo '<p>Riddle answer # ' .$userdata[user_riddle].'</p>';
// Request the text of selected riddle
global $userdata;
$currentanswer = @mysql_query("SELECT answer FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle]");
if (!$currentanswer) {
die("<p>Error performing query: " . mysql_error() . "</p>");
}
// Display the text of selected riddle in a paragraph
while ( $row = mysql_fetch_array($currentanswer) ) {
$user_answer = $row['answer'];
echo '<p>Riddle answer '.$user_answer.'</p>';
}
// Check answer and update user riddle by one increment if correct
$youranswer = $_POST['youranswer'];
if ( $youranswer == $user_answer )
{
global $userdata;
echo( 'Well done ' .$userdata[username].', that was the right answer' );
$incrementin = $userdata[user_riddle] + 1;
global $userdata;
$sql = 'UPDATE `phpbb_users` SET `user_riddle` = user_riddle + 1 WHERE `username` = \'anonymous\' ';
if ( @mysql_query($sql) ) {
echo('<p>Update affected ' . mysql_affected_rows() .
' rows.</p>');
else {
die('<p>Error performing this effing update: ' . mysql_error() .
'</p>');
}
echo '<p>number is '.$incrementin.', okay?</p>';
} else {
echo( 'bad luck' );
}
// Request the text of selected riddle
global $userdata;
$currentriddle = @mysql_query("SELECT riddle FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle] ");
if (!$currentriddle) {
die("<p>Error performing query: " . mysql_error() . "</p>");
}
// Display the text of selected riddle in a paragraph
while ( $row = mysql_fetch_array($currentriddle) ) {
$user_riddle = $row['riddle'];
echo '<p>Riddle '.$user_riddle.'</p>';
}
?>
The // Request the text of selected riddle part of the page is the part that is not querying the db on the UPDATE information that has just been entered - so I assume a reload must be used here.
Cheers
Mxx
Page is displayed taking info from a database depending on a particular field (user_riddle) of the user. Page also has a form at the end.
User enters details to the form and submits - which reloads the page.
If the data is false. the page reloads as before - no problem here.
If the data is true, user_riddle increments by 1, which should result in a different set of info coming out of the database.
However, the script runs as before, and I need to manually refresh the page for the database to be queried again to get the new info. I would like to reload the page after the user_riddle has incremented...how can I do this?
<?php
// Request the user_riddle number
global $userdata;
echo '<p>Riddle answer # ' .$userdata[user_riddle].'</p>';
// Request the text of selected riddle
global $userdata;
$currentanswer = @mysql_query("SELECT answer FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle]");
if (!$currentanswer) {
die("<p>Error performing query: " . mysql_error() . "</p>");
}
// Display the text of selected riddle in a paragraph
while ( $row = mysql_fetch_array($currentanswer) ) {
$user_answer = $row['answer'];
echo '<p>Riddle answer '.$user_answer.'</p>';
}
// Check answer and update user riddle by one increment if correct
$youranswer = $_POST['youranswer'];
if ( $youranswer == $user_answer )
{
global $userdata;
echo( 'Well done ' .$userdata[username].', that was the right answer' );
$incrementin = $userdata[user_riddle] + 1;
global $userdata;
$sql = 'UPDATE `phpbb_users` SET `user_riddle` = user_riddle + 1 WHERE `username` = \'anonymous\' ';
if ( @mysql_query($sql) ) {
echo('<p>Update affected ' . mysql_affected_rows() .
' rows.</p>');
else {
die('<p>Error performing this effing update: ' . mysql_error() .
'</p>');
}
echo '<p>number is '.$incrementin.', okay?</p>';
} else {
echo( 'bad luck' );
}
// Request the text of selected riddle
global $userdata;
$currentriddle = @mysql_query("SELECT riddle FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle] ");
if (!$currentriddle) {
die("<p>Error performing query: " . mysql_error() . "</p>");
}
// Display the text of selected riddle in a paragraph
while ( $row = mysql_fetch_array($currentriddle) ) {
$user_riddle = $row['riddle'];
echo '<p>Riddle '.$user_riddle.'</p>';
}
?>
The // Request the text of selected riddle part of the page is the part that is not querying the db on the UPDATE information that has just been entered - so I assume a reload must be used here.
Cheers
Mxx