Siggles Posted February 19, 2008 Share Posted February 19, 2008 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. Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/ Share on other sites More sharing options...
trq Posted February 19, 2008 Share Posted February 19, 2008 Replace... echo "Prediction Inserted successfully"; with... header("Location: " . $_SERVER['PHP_SELF']); Be sure to arrange you code so that no output is sent to the browser prior to calling the header(0 function though. Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/#findComment-470449 Share on other sites More sharing options...
Siggles Posted February 19, 2008 Author Share Posted February 19, 2008 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? Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/#findComment-470460 Share on other sites More sharing options...
trq Posted February 19, 2008 Share Posted February 19, 2008 Post your code. Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/#findComment-470463 Share on other sites More sharing options...
Siggles Posted February 19, 2008 Author Share Posted February 19, 2008 I cant get it to post the code, keeps displaying page cannot be found. Even in the CODE brackets. I have put it here though if you dont mind having a look http://www.independentmillwall.com/code.txt Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/#findComment-470475 Share on other sites More sharing options...
Siggles Posted February 19, 2008 Author Share Posted February 19, 2008 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 Link to comment https://forums.phpfreaks.com/topic/91862-refreshing-page-after-submitting-form-to-php_self/#findComment-470521 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.