Jump to content

Refreshing Page after submitting form to PHP_SELF.


Siggles

Recommended Posts

Hi,

 

I have forms that use the PHP_SELF action to send data to same page. This all works fine. But I then have to refresh the page a second time to see the latest info that is gathred by SQL statements. Is there any way the latest info can be seen after hitting submit on the form. See my code...

 

<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">

<td><input type="text" name="resultmfc" size="1"></td>

<td><input type="text" name="resultother" size="1"></td>

<td><input type="submit" name="submit" value="Add!"></td>

<input type="hidden" name="opt" value="addprediction" />

<input type="hidden" name="id" value="<? echo $cid; ?>">

<input type="hidden" name="dropdown" value="0" />

</form>

 

then the opt value runs...

 

switch($_POST['opt']) {

case "addprediction":

 

$datecreated=date("Y-m-d H:i:s");

$pid=$_POST['id'];

$pusername=$session->username;

$presultmfc=$_POST['resultmfc'];

$presultother=$_POST['resultother'];

 

//Checks for 0-9 in form fields

if (eregi('^[0-9]$', $presultmfc) && eregi('^[0-9]$', $presultother)) {

mysql_query("INSERT INTO predictions (datecreated, username, id, resultmfc, resultother) VALUES ('$datecreated', '$pusername', '$pid', '$presultmfc', '$presultother')");

echo "Prediction Inserted successfully";

} else {

echo "Enter a number between 0 - 9";

}

 

break;

 

But the info entered in to the MySQL database is not seen unless you refresh again.

Hi, I moved the php block of code to the top of the page (before the HTML tags) but didin't put in your header suggestion. The refresh now works okay but the font changes when the screen refreshes, as if it is skipping the CSS. Why would that happen?

Never mind, I figured it out. I moved the php code (with no changes) to the top of the page, just after the body tag. Must have been the order of things that didnt refresh the page correctly - your post gave me that clue, thank you.

 

I will find another way of outputting 'prediction inputted successfully' etc elsewhere on the page using variables and ifs. :-D

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.