Despite good help, still can't get this form post working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Despite good help, still can't get this form post working

Post by mikeb »

Hi,

I posted for some help as a php newbie. Great response but night #3 and it's still not working. Been through a re-install of php etc. I can do what I like with variables on one php page such as adding, subtracting variables etc. so php SEEMS to be working on my server. My problem is that I'm trying to post a simple set of variables from a form on a html page to a receiveing action page. When I post the form, there is simple a blank page! My html header and footer source code is viewable when I look at the source code, but the php code has not been processed.

There is no error in my Apache log to indicate anything going wrong. I'm using php 4 and Apache 2 on a W2K PC. Can someone give me a simple piece of code to check whether a form post is working or not.

I'm an experienced html and ColdFusion coder so I'm not new to web coding and am pretty sure my html is ok in my samples. Is there a possible php configuration error that I'm not picking up? :?
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

Code: Select all

<?php

phpinfo();

?>
If that runs, PHP is working. Next step would me to let us look at some code (post it here).
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

to see if php is working corectly, create a new page with php extention and include the following code:

Code: Select all

<?
phpinfo();
?>
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Ran php info command.
Everything worked fine. Html output showing my system settings
==========================================
Here's my form code (stripped to the bare essentials)
==========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>

<form method="post" action="formaction.php">
<input type="text" name="FirstName"><br>
<input type="submit" name="submit">
</form>

</body>
</html>
============================================
Here's my action page
============================================
<html>
<head>
<title>hello</title>
</head>
<body>
<?php
echo "$_POST['FirstName']";
?>
</body>
</html>
============================================
When I post this form, I get no error, no error in my Apache
log either. Here is the processed html from 'view source'
============================================
<html>
<head>
<title>hello</title>
</head>
<body>
</body>
</html>
============================================
Here is an error messag I get when I single quote the variable
as ['variable'] on the action page as suggested on the forum
============================================
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE'
or `T_NUM_STRING' in C:\webroot\Sandbox\phpLearning\
formaction.php on line 11
============================================
I feel myself moving back to ColdFusion!!!


Mike
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

Try removing the double quotes around the echo command but leave the singles around the form name. It should work.

Keith
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

mikeb wrote:I feel myself moving back to ColdFusion!!!
Nooooo!! Yourre doing great! Just a little error...that's all :wink:
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Took the double quotes off the echo command. Can't find the 'Form Name' as I haven't named the form? Still getting clean html when I view source!

ps. I've a biker friend in work and I'll send him your url!

Mike
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

I guess he means:

Code: Select all

echo $_POST&#1111;'FirstName'];
not:

Code: Select all

echo "$_POST&#1111;'FirstName']";
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Nope! still not working with Red Hair's code. Syntactical nightmare! I've still got the clean html with no sign of php being processed - although, no error messages. This is going to turn out to be something really stupid on my part.
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Can't wait to start on my SQL connections!
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

ehhh... ok...hey i'm just a newbie ;-)
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Odd, I just copied and pasted your code onto my server and with redhair's correction it ran fine. It must be a configuration problem.

Something is not right.. If Apache wasn't processing the PHP at all then you would see it in the source. I know this is fundamental but you need to confirm your action is submitting to the correct PHP page. I've been so bone headed before to have a similar problem only to turn out I was working on the wrong page... Is your server accessible from the internet? If so, can you give us the URL to the phpinfo file? Not sure what I expect to find but it couldn't hurt.
Last edited by mrvanjohnson on Thu Jul 10, 2003 6:25 pm, edited 1 time in total.
mikeb
Forum Commoner
Posts: 60
Joined: Tue Jul 08, 2003 4:37 pm
Location: Dublin, Ireland

Post by mikeb »

Thanks Red Hair. That was not supposed to be a bad comment. I really appreciate the help. :oops: This forum is brilliant, really like the quick response from people who know their stuff better than me. I've got to go get some sleep (12:30am here), I've got a client meeting in the morning.

Thanks for the help and I'll keep the faith. I know php is cool - just need to get to know it,

cheers,

Mike :wink:
User avatar
redhair
Forum Contributor
Posts: 300
Joined: Fri May 30, 2003 4:36 pm
Location: 53.23N-6.57E
Contact:

Post by redhair »

No problem at all...it was not meant that way.
I just was as lost as you are with your problem. When i can't find the solution...i feel like a newbie :wink:
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post by jason »

When you wake up, could you do two things. First, give us an update of the exact code you are using on your action page (the one giving you the problem), and also, if you could, the Url where we can test this out. From what I see, the suggestions so far should have worked. Also, one final request, a Url to your phpinfo() page, so we could take a look at the configuration. Maybe something is barfed, but I doubt it.

Code: Select all

<html>
<head>
<title>hello</title>
</head>
<body>
<?php
echo $_POST['FirstName'];
?>
</body>
</html>
This is what you should have.
Post Reply