My project is about a school admin I have a page called : createClass.php, where user inserts grade, profile etc. When he press "submit" page called createdClass.php is loading. Inside this page I have all code which insert data into database and also an "if" structure which says : "Class already exists" if in database is another class with same specifications. Also in second page (createdClass.php) i have a small table which shows the place of each student. First time all cells are green (this means that place is free) and if i click one of them appear a popup window which let me to add info about student from that place. If a place is busy the cell will be red (take a look here : http://screencast.com/t/NzM2YzYxNjct). The big problem is that the cell will be red only after refresh the page (the place ask for data from database). If I pre开发者_JAVA技巧ss refresh appears "class already exists". To test the code i added in a comment all lines which verify and add respectively classroom . I think my problem can be solved with ajax. I'm waiting for an answer. Regards Stefan
To refresh the original window from the popup, use this piece of javascript:
window.opener.location.refresh();
You must redirect the user to another page after inserting data (after POST request, generally speaking).
Change the form in createClass.php to point to the same page and move your database insert code to that file.
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// insert the data here
header('Location: /createdClass.php');
exit();
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
...
</form>
(Update) The flow will go like this:
- The user is shown a form in createClass.php
- When user submits the form, the submission is handled in the same createClass.php, which inserts database row and then shown no page but tells the browser to go to 'createdClass.php'.
- Now browser loads createClass.php, which just shows the student table (but makes no database inserts!). Now you can refresh createClass.php as many times as you want without side effects.
Note that the above may not solve all your issues. Without more information (or code) I cannot help more.
精彩评论