Click to See Complete Forum and Search --> : Problems with POST


jorgemark
06-11-2008, 03:27 PM
Hi, I'm a student working on a project, but I'm not a computer science student so I don't know exactly what I'm doing. I'm using Xampp as my PHP server (on a PC) and there's a good chance that might be the problem, only I don't know what it is. I'm only using Xampp for development so I'm not even sure this problem would carry over when the page is finally "published". I've spent a lot of frustrating time on this so anyone with any kind of answer (or direction to point me in) would help a lot!

My main problem is that the POST variables from the HTML side are not being posted to the php document. I've looked through some of the previous posts on this forum and for them changing the $_POST to $_REQUEST in the PHP form solved the problem, unfortunately it didn't for me. I'm not doing much more than PHP, so the problem must be somewhere in here, or with the Xampp server. It's either something very simple that I've overlooked (this is my first PHP project) or it's something else I am not at all familiar with. There are about 71 variables being posted, and they all match up with the HTML form, if that matters.

Here's what it looks like on the HTML side.

<FORM ACTION="pc2.php" method=post>

<p><h1>F E C</h1><br></p>

<p><b>Paname:</b> <input type="text" name="paname" size="25"> <br>
<b>M Number:</b> <input type="text" name="mnumber" size="10" maxlength="10"> <br>
<b>Exdate:</b> <input type="text" name="exdate" size="8" maxlength="8"> </p>

Here's what it looks like where it defines the variables in pc2.php:

<body style="font-family: Arial">
<h1><br>
F E C</h1>
<p>&nbsp;</p>

<?php

$paname = $_POST['paname'];
$mnumber = $_POST['mnumber'];
$exdate = $_POST['exdate'];

Here's where it tries to display those variables, in the same pc2.php:


echo "<p><b>Paname:</b> " . echo $paname . echo "<br>
<b>M Number:</b> " . $mnumber . echo "<br>
<b>Exdate:</b> " . $exdate . echo "<br></p>"

I've also tried it like this:

<p><b>Patient name:</b> <?php print $paname ?><br>
<b>M Number:</b> <?php print $mnumber ?><br>
<b>Exdate:</b> <?php print $exdate ?><br></p>

I know something is wrong, but what? How far am I off the path?

Yelgnidroc
06-11-2008, 05:59 PM
Need to see the whole scripts if possible

SyCo
06-11-2008, 07:56 PM
When you're debugging and you hit a wall keep simplyfying until you find the solution. Isolate the potential problem area. Right now the problem is either the script or the server. So first thing to try is a really simple script.

Copy this, save it and click the button, You should see the time update every time you click the button. It simply posts a timestamp back to the page. If this works then it's your script.


<form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>">
<input type="hidden" id="postedtime" name="postedtime" value="<?=time()?>">
<input type="submit" value="Hit me!">
</form>

<?
if(isset($_POST['postedtime'])){
echo date("G:i:s T",$_POST['postedtime'])." - this works so it looks like it's the script!<br><br>";
}
?>


Aslo this kind of thing

$paname = $_POST['paname'];

makes debugging that much harder. Ther's no reason to rename the var and it's clear even in the most complex script where the var $_POST['paname'] came from.

jorgemark
06-12-2008, 01:00 PM
I tried running that script you suggested, Syco, and this what I got:

Access forbidden!

You don't have permission to access the requested object. It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403
localhost
06/12/08 13:53:02
Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5

I'm not sure if this is a server error or a problem with permissions on the computer (in the last couple of days I was moved onto a network computer) but it is a start, at least. I will try to clarify this by logging directly onto the computer and let you know.

Also, forgive me if I'm being dull, but does not renaming the var mean that in every instance where I would have used the rename I can just use $_POST['paname'] instead? I did not know that. It does seem like a unnecessary step if that's the case.

NogDog
06-12-2008, 01:08 PM
Did you save the file with a .php suffix?
Did you save it within the web document directory (probably "htdocs" with XAMPP)?
Did you access it via a URL (e.g.: "http://localhost/test.php") rather than a File->Open or double-clicking its icon?

jorgemark
06-12-2008, 01:08 PM
I've run the server and script again with full permissions. I'm getting the same error message, so does that mean that whatever is rotten is rotten with the server?

EDIT:


Did you save the file with a .php suffix?
Did you save it within the web document directory (probably "htdocs" with XAMPP)?
Did you access it via a URL (e.g.: "http://localhost/test.php") rather than a File->Open or double-clicking its icon?


Yeah. And it's weird. With some of my "tests" I can make php count and add numbers, but I can't detect any real differences in the script.

EDIT 2:

"; } ?>

I'm also getting that underneath the "Hit Me!" button in the browser, if that helps.

SyCo
06-12-2008, 01:24 PM
I'm also getting that underneath the "Hit Me!" button in the browser, if that helps.

on page load or after you hit the button?

and it could be worse your page could look like this
http://www-ext.impmc.jussieu.fr/error/HTTP_FORBIDDEN.html.var/

Have you set up any virtual hosts?

jorgemark
06-12-2008, 01:44 PM
on page load or after you hit the button?

On page load, the error message above is what I get after I hit the button. And I am glad I'm not getting that error page you linked! Though I suppose there is something hopeful about knowing that everything is wrong, you just start again. Also, I haven't set up any virtual hosts... as far as I know? What does that mean?

SyCo
06-12-2008, 02:00 PM
Virtual hosts allow for hosting multiple domains on one apache server.

It's definitely a server issue but if you don't have virtual hosts I don't know what it could be. Maybe back up you web files and re-install. I've never had a problem with the default install of LAMP or WAMP.

jorgemark
06-12-2008, 03:09 PM
I think I'll try that, I'll let you know what happens.