Jump to content

Archived

This topic is now archived and is closed to further replies.

yanks6rule

Problem with Form reload

Recommended Posts

I have this page where a member is allowed to add guests to an event they are attending. The way the page is setup is as follows:

-Check for Session to make sure member is logged in
-Query guest table, to check for any guests that have been entered by this member
-If guest exists put them in a table for display
-else say no registered guests
-Show a form that allows for a new guest to be inserted
-insert new guest into guest table
-unset($_POST)
-then include the page again

The last part is to reload the table on top to show all guests that have been added where they can remove or edit.

The problem I am having is that when I hit submit the new page is loaded underneath the table from the original page. Meaning if I have a guest already added when I add a second guest, A table with the first guest stays and then underneath that a new table comes up with both guests and then the form. Is there a way around this, I can't use headers because I have already started output and I don't want to use output buffering if I don't have to because I heard there is a lot of security issues if not used properly and I don't have enough experience to make sure I am not buffering without sending sensitive information.

If you can help, great.

Thanks
Yanks

Share this post


Link to post
Share on other sites
well it's kind of hard to know how to fix your problem without you showing code. but offhand i'd say check your frames if you have them, make sure they are being updated in the right place. if it's not that, then check your loops and conditions to see if you aren't inadvertantly double iterating the table, or maybe there are 2 conditions that turn out to be true when you want to only do one or the other in which you should have if/else not if/if

failing all that, what do you mean, "include the page again?" do you mean to say that the last line of code involves doing an include of the [i]same[/i] script? that's probably your problem right there. if you want the page to reload after the user submits, in your form tag add

<form method = 'post' [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]action='$PHP_SELF'[!--colorc--][/span][!--/colorc--]>

and ditch that include.

Share this post


Link to post
Share on other sites
[!--quoteo(post=373577:date=May 13 2006, 04:11 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 13 2006, 04:11 PM) [snapback]373577[/snapback][/div][div class=\'quotemain\'][!--quotec--]
well it's kind of hard to know how to fix your problem without you showing code. but offhand i'd say check your frames if you have them, make sure they are being updated in the right place. if it's not that, then check your loops and conditions to see if you aren't inadvertantly double iterating the table, or maybe there are 2 conditions that turn out to be true when you want to only do one or the other in which you should have if/else not if/if

failing all that, what do you mean, "include the page again?" do you mean to say that the last line of code involves doing an include of the [i]same[/i] script? that's probably your problem right there. if you want the page to reload after the user submits, in your form tag add

<form method = 'post' [!--coloro:blue--][span style=\"color:blue\"][!--/coloro--]action='$PHP_SELF'[!--colorc--][/span][!--/colorc--]>

and ditch that include.
[/quote]


I can include my code if you would like it just is rather lengthy that is why I tried to pair it down so that I could explain it best.

I have kind of fixed my problem, but I know it is not the right way of doing it. I am going to include some of my code here to see if it will help, if you want more let me know.

I am calling a page called guest_reg.php, which is displayed below:
<?php
include "start_session.php";
//Start Coding
$event = $_SESSION['event'];
$pid = $_SESSION['pid'];
echo "<p><font size=+3>$event</font></p>";
include "mysql_connect_snacks.php";
mysql_select_db("chemdocs");
$guest_qry = "SELECT * FROM guest WHERE pid='$pid'";
$guest_res = mysql_query($guest_qry) or exit(mysql_error());
$num = mysql_num_rows($guest_res);
if ($num != 0) {
$guest_table = '
<table width =\"50%\">
<tr><th colspan=5><div align="center">Guests That Have Been Added</div></th></tr>
<tr><th>Check</th><th>Last Name</th><th>First Name</th><th>M.I.</th><th>Relation</th></tr>';
$i = 0;
while (($i < $num) && ($row = mysql_fetch_array($guest_res))) {

$guest_table .= '
<tr>
<td width=5%><input type="checkbox" name="update['. $row['gid'] .']" value="1" /></td>
<td><div align="center"><span class="black_text">' . $row['glastname'] . '</span></div></td>
<td><div align="center"><span class="black_text">' . $row['gfirstname'] . '</span></div></td>
<td><div align="center"><span class="black_text">' . $row['mi'] . '</span></div></td>
<td><div align="center"><span class="black_text">' . $row['relation'] . '</span></div></td>
</tr>';

$i++;
}
$guest_table .= '</table>';
echo "$guest_table";

} else {
echo "No guests are yet registered";
}

include "forms.php";

?>

Forms.php is just a form with first, last, MI and relation and then I do some error check and here is the last bit, that I did a quick fix on by using an HTML refresh function. If you can let me know if there is a better way to make the page show up with a table with all guests of a member shown and then the form to add another guest and everytime they hit add guest a guest will be added to the table let me know.

//Select DB:
mysql_select_db("chemdocs");
//Set MI variable
$mi = $_POST[mi];
$pid = $_SESSION['pid'];
//Insert Statement
$query = "INSERT INTO guest
SET glastname = '" . mysql_real_escape_string($glastname) . "',
gfirstname = '" . mysql_real_escape_string($gfirstname) . "',
mi = '" . mysql_real_escape_string($mi) . "',
relation = '" . mysql_real_escape_string($relation) . "',
pid = '". mysql_real_escape_string($pid) ."'";
$result = mysql_query($query) or die(mysql_error());
echo "guest added successfully";
unset($_POST);
function Refresh_Page($page)
{

$refresh='<html><META HTTP-EQUIV="Refresh" CONTENT="0; URL='.$page.'"></html>';
echo $refresh;

}
Refresh_Page('http://snacks.chem.umass.edu/session/guest_reg.php');
}
}

THanks

Share this post


Link to post
Share on other sites

×

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.