drwex: (Default)
[personal profile] drwex
As I noted before, both of these are files that worked fine on the old Apache installation. But here they are. It works properly, accesses the database and constructs dropdowns with the proper values:
<?php
$title="Random Monster Tables";

include("header.php");
?>

<table border=1 cellpadding=0 cellspacing=0>
<tr><td>
<form method="post" action="appearing-table.php">
<table border=0 cellpadding=3 cellspacing=3>
<tr><td align="right">CR:</td><td><select name="cr">
<?php
for ($index=1; $index<=20; $index++) {
  printf("<option>%s",$index);
}
?>
</select></td></tr>
<tr><td align="right">Habitat:</td><td><select name="habitat">
<?php
$res=mysql_query("SELECT id, Name FROM habitat_names ORDER by id",$db);
while ($row=mysql_fetch_array($res)) {
  printf("<option value=\"%s\">%s",$row["id"],$row["Name"]);
}
?>
</select></td></tr>
<tr><td colspan=2 align=center><input type="submit" value="Generate Table">
<input type="reset" value="Reset"></td></tr>
</table>
</form>
</td></tr></table>

<P><a href="appearing-full.php">View Raw Data</a></P>
<?php
$timestamp=gmdate("D, d M Y H:i:s") . " GMT";
include("footer.php");
?>
This is B.php, also known as appearing-table.php, the form target from the above. The failure is in the 'if' test to make sure the form variables are set. If I insert a printf() to show $cr it shows blank.
<?php
$title="Generated Random Monster Table";

include("header.php");
//make sure the form variables are set
if (isset($cr) && isset($habitat)) {
printf("<p>Inside the if statement</p>");
  $result=mysql_query("SELECT Name FROM habitat_names WHERE id=$habitat");
  $item=mysql_fetch_array($result);
  printf("<h3>%s at CR %s</h3>\n",$item["Name"],$cr);
  $cr = "cr" . $cr;
?>
<table border=1 cellpadding=3 cellspacing=1>
<tr><th>Monster</th><th>Number Appearing</th></tr>
<?php
  $result=mysql_query("SELECT Name, $cr FROM monsters AS m JOIN APPEARING AS a JOIN
 habitats AS h WHERE h.monsterid=m.id AND h.existsin = \"X\" AND h.habitatid = 
$habitat AND a.$cr != \"NULL\" AND a.monsterid = m.id ORDER BY m.name");
  while ($row = mysql_fetch_array($result)) {
    printf("<tr><td>%s</td><td>%s</td></tr>\n",$row["Name"],$row[$cr]);
  }
}
?>
</table>

<a href="generate-table.php">Generate another table.</a>
<?php

$timestamp=gmdate("D, d M Y H:i:s") . " GMT";
include("footer.php");
?>
I thought it might be an issue of directory permissions (which is what most of the Web pages suggest) but that doesn't seem to be the case because appearing-full.php works if you click the link to navigate to it. The issue seems to be just with the form submit/form variables.

Date: 2008-12-05 04:53 am (UTC)
From: [identity profile] awfief.livejournal.com
Again, what is register_globals set to in your php.ini?

Also:
http://www.tizag.com/phpT/examples/formvar.php

Have you tried to see the value of

$_POST["cr"]

Have you tried with something more simple first? Because I don't see where you're giving the options in your web form an actual value. So it's possible you *are* actually getting the value of "cr", but because you haven't actually assigned a value to it, the value is NULL.

You do assign a value for habitat. Do you get a value for that?

Try with this first:

[INPUT TYPE=TEXT NAME="cr"] (I tried using angle brackets and my code was eated! pretend [ = < and ] = > and you'll be set.)

and see what you get when you type something into the checkbox, submit the form, and see if you get the variable assigned to the value of what you typed.

First determine if it's actually whether or not the variables are being passed, and then you can deal with the fact that "cr" doesn't even have any values *to* assign, even if you do select an option from the list.
Edited Date: 2008-12-05 04:55 am (UTC)

Date: 2008-12-05 05:08 am (UTC)
From: [identity profile] golux-org.livejournal.com
I'm pretty sure this is the right direction. Since PHP 4.2, format $cr for form variable 'cr' is not recognized. So if you are migrating from a version of PHP before 4.2, this problem is expected to occur. See the warning box at the top of this page about "a major change in PHP."

http://us2.php.net/variables.predefined

A simple fix is to use $_POST['cr'] instead of $cr.

Re: Grr, argh

Date: 2008-12-05 07:21 am (UTC)
From: [identity profile] points.livejournal.com
Sorry, I queued your post up for answering, and I got majorly work-idled. Your 'suddenly working' sounds like your browser might have been caching. Anyhow, ping me on IM if you're playing with this now and want some additional help?

Re: Grr, argh

Date: 2008-12-05 11:08 pm (UTC)
From: [identity profile] points.livejournal.com
I'm on AIM, Yahoo, MSH and ICQ. Drop me email with which you prefer, and I can give you a userid.

Date: 2008-12-05 07:19 am (UTC)
From: [identity profile] points.livejournal.com
This is, I believe the correct answer. PHP depreciated 'register globals' quite a while back due to huge security issues. $_POST['name'] is the proper accepted manner to extract form variables from a 'post' style form, and $_GET['name'] for get-style. I'd strongly recommend using this, as opposed to changing your php.ini.

Date: 2008-12-05 04:58 am (UTC)
coraline: (bites)
From: [personal profile] coraline
can you please put this behind a cut? i realize it's my own fault that it's messing up the width of my page (i could choose a format which that was not true of) but...

Date: 2008-12-05 05:01 am (UTC)
From: [identity profile] caulay.livejournal.com
Seconded, those long literal lines mean everything is messed up for me.

Date: 2008-12-05 05:00 am (UTC)
From: [identity profile] caulay.livejournal.com
Also, to follow up on what [livejournal.com profile] awfief said, have you tested B by going to it directly with the parameters set in the URL.

For example:

http://localhost:80/b.php?cr=Some_Value&habitat=Some_Other_Value

If that works then your problem is passing the values from the first page. If it doesn't work the PHP is not picking up the passed in values for the second page.

Good luck.

Profile

drwex: (Default)
drwex

July 2021

S M T W T F S
    123
45678910
11121314151617
1819 2021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 10th, 2026 01:43 pm
Powered by Dreamwidth Studios