PDA


View Full Version : Form POST Problem in PHP Page


matmen
07-24-2005, 05:48 PM
I have a PHP script that uses a popup calendar to capture a date from the user. After the user selects a date and clicks the submit button, I want to call the same PHP script passing in the date. If the script is called without a date (the first time the user accesses it), it just displays results from the past week rather than from a specific day.

The problem is that the user-supplied date isn't being passed into the script. It works just fine when I use the script outside of vBadvanced. I'm using the vBadvanced page url as the action attribute of the form tag.

Can someone please help?

Thanks in advance!

Brian
07-24-2005, 06:32 PM
Can you post a link to where you're using this script so I can get a better idea of how you're using it?

matmen
07-24-2005, 07:28 PM
Can you post a link to where you're using this script so I can get a better idea of how you're using it?
http://illinoismatmen.com/cmps_index.php?page=dualresults

You will see "This Week's Dual Results" as the title of the table the first time you login because you have not selected a date. Once you select a date (i.e. 2005-07-24) using the popup calendar and click "View Results" the title should change to "Dual Results for 2005-07-24" and only that day's results (none for July 24th) should be displayed. Let me know if you need more information to diagnose the problem.

Thanks for your help!

Brian
07-24-2005, 10:23 PM
Can you post the PHP file you're using for this as well?

matmen
07-25-2005, 12:02 AM
Here is the PHP source minus the database connection information.

<?php

//make db connection(s)
$db = mysql_connect("localhost", "", "");
if (!$db) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db("", $db);
if (!$db_selected) {
die ('Can not use results database: ' . mysql_error());
}

$tm = time();
$tm -= 7*24*60*60;
$last_week = date("Y-m-d", $tm);

if ($dual_date) {
$get_results = "SELECT dual_date, home.team_name, home_score, visitor.team_name, visitor_score, dual_id FROM dual, team home, team visitor WHERE dual_date = '{$dual_date}' AND home_team_id = home.team_id AND visitor_team_id = visitor.team_id";
}
else {
$get_results = "SELECT dual_date, home.team_name, home_score, visitor.team_name, visitor_score, dual_id FROM dual, team home, team visitor WHERE dual_date >= '{$last_week}' AND home_team_id = home.team_id AND visitor_team_id = visitor.team_id ORDER BY dual_date DESC";
}

$result = mysql_query($get_results, $db);
if (!$result) {
die('Invalid query: ' . mysql_error());
}

?>

<tr>
<td bgcolor="#F5F5FF" class="smallfont">

<form name="choose_date" action="cmps_index.php?page=dualresults" method="POST">
Choose a Date: <input name="dual_date" value="" size="11" readonly><a href="javascript:void(0)" onclick="if(self.gfPop)gfPop.fPopCalendar(document.choose_date.dual_date);return false;" HIDEFOCUS><img class="PopcalTrigger" align="absmiddle" src="popcal/calbtn.gif" width="34" height="22" border="0" alt=""></a>
<input type="submit" name="submit" value="View Results">
</form>
<br /><br />
<table align="center" border="0" cellpadding="1" cellspacing="1" class="tborder" width="100%">
<tr>
<?php
if ($dual_date) {
?>
<td class="thead smallfont" colspan="6" align="center"><b>Dual Results for <?php echo $dual_date; ?></b></td>
<?php
}
else {
?>
<td class="thead smallfont" colspan="6" align="center"><b>This Week's Dual Results</b></td>
<?php
}
?>
</tr>
<tr>
<td class="tcat smallfont" align="center"><b>Date</b></td>
<td class="tcat smallfont" align="center"><b>Home</b></td>
<td class="tcat smallfont" align="center"><b>Score</b></td>
<td class="tcat smallfont" align="center"><b>Visitor</b></td>
<td class="tcat smallfont" align="center"><b>Score</b></td>
<td class="tcat smallfont" align="center">&nbsp;</td>
</tr>
<?php
while( $myrow = mysql_fetch_row($result) ){
?>
<tr>
<td class="$bgclass smallfont" align="center"><?php echo $myrow[0]; ?></td>
<td class="$bgclass smallfont" align="center"><?php echo $myrow[1]; ?></td>
<td class="$bgclass smallfont" align="center"><?php echo $myrow[2]; ?></td>
<td class="$bgclass smallfont" align="center"><?php echo $myrow[3]; ?></td>
<td class="$bgclass smallfont" align="center"><?php echo $myrow[4]; ?></td>
<td class="$bgclass smallfont" align="center"><a href="results_detail.php?dual_id=<?php echo $myrow[5]; ?>">Details</a></td>
</tr>
<?php
}
?>
</table>

<iframe width=174 height=189 name="gToday:normal:agenda.js" id="gToday:normal:agenda.js" src="popcal/ipopeng.htm" scrolling="no" frameborder="0" style="visibility:visible; z-index:999; position:absolute; top:-500px; left:-500px;">
</iframe>

Brian
07-25-2005, 12:29 AM
Try adding this at the top of the file, just below the <?php tag:

$dual_date = addslashes($_REQUEST['dual_date']);

matmen
07-25-2005, 12:39 AM
That did it! Can you please explain why that fixed the problem?

Thanks again Brian!

Brian
07-25-2005, 12:48 AM
Register globals is turned off in vB, so you have to use $_REQUEST['var'], $_POST['var'], and etc when using variables from the URL.

matmen
07-25-2005, 12:59 AM
Got ya. Thanks for the info.

On a semi-related topic, I notice that some of the basic style isn't available to me from the PHP script. For example, when I use cellpadding="$stylevar[cellpadding]" cellspacing="$stylevar[cellspacing]" in my table declaration, the values are set to 0, but other modules (i.e. my menu) get different values. I had to manually set the table cellpadding and cellspacing to 1. Also, the cells that use the tcat and thead classes aren't the same height as the other cells on the page that use the same classes. You'll notice this by comparing the cells in the dual results table to the cells in the main menu. Can you help me out? Thanks!

Brian
07-25-2005, 12:31 PM
There's not really a reason I can think of why you shouldn't be able to use the $stylever variables in the script...
For the spacing issues, it looks like the cause of that is you have your cellpadding set to 1 in the PHP script, but 6 on your forums.