Forum Moderators: coopster

Message Too Old, No Replies

form problem

         

tottyovi

3:05 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



Hello,
I'm new in PHP and I'm still learning.
I just created a form and I have a problem.
Here you have the page source

HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Html form</title>
</head>
<body>

<form action="handle_form.php" method="post">
<fieldset><legend>Enter your information in the form below:</legend>

<p><b>Name:</b><input type="text" name="name" id="name" size="20" maxlength="40" /></p>
<p><b>Email Adress:</b> <input type="text" name="email" id="name" size="40" maxlength="60" /></p>

<p><b>Gender:</b><input type="radio" name="gender" id="gender" value="M" />Male<input type="radio" name="gender" id="gender" value="F" />Female</p>
<p><b>Age:</b><select name="age">
<option value="0-29">Under 30</option>
<option value="30-60">Betwen 30 and 60</option>
<option value="60+">Over 60</option></select></p>

<p><b>Comments:</b><textarea name="comments" id="comments" rows="3" cols="40"></textarea></p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Submit my information" /></div>
</form>

</body>
</html>

PHP:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Handle form</title>
</head>

<body>
<?php
//Creaza o forma prescurtata pentru datele din formular.

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comments = $_REQUEST['comments'];
//Nefolositeage, gender, submit

//Afiseaza informatiile transmise.

echo "<p>Thank you, <b>" . $name . "</b>, for the following comments:<br /><tt>" . $comments . "</tt></p><p>We will reply to you at <i>" . $email . "</i>.</p>";

?>
</body>
</html>

My problem that after I complete this html form it's appearing this(without dates from my form) :

Thank you, " . $name . ", for the following comments:
" . $comments . "

We will reply to you at " . $email . ".
"; ?>

I'm using wamp. Do you know what's the problem, please?
Thank you

tottyovi

6:23 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



please,somebody

jatar_k

7:14 pm on Jun 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



so then it looks like the php isn't getting parsed, or at least not properly

is this your first php file or do you have other ones that work?

tottyovi

7:26 pm on Jun 29, 2009 (gmt 0)

10+ Year Member



yes, other works...

denisl

9:41 pm on Jun 29, 2009 (gmt 0)

10+ Year Member Top Contributors Of The Month



Have you tried replacing
echo "<p>Thank you, <b>" . $name . "</b>, for the following comments:<br /><tt>" . $comments . "</tt></p><p>We will reply to you at <i>" . $email . "</i>.</p>";

with
echo "<p>Thank you, <b>$name</b>, for the following comments:<br /><tt>$comments</tt></p><p>We will reply to you at <i>$email</i>.</p>";

rocknbil

4:31 am on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



or even

$msg = "<p>Thank you, <b>$name</b>, for the following comments:<br /><tt>$comments</tt></p><p>We will reply to you at <i>email</i></p>";

echo $msg;

tottyovi

7:37 am on Jun 30, 2009 (gmt 0)

10+ Year Member



denisl and rocknbil: I tried both possibilities and the same thing.

penders

10:10 am on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Slight error with your form, although this does not explain the problem you are getting:
<p><b>Name:</b><input type="text" name="name" id="name" size="20" maxlength="40" /></p>  
<p><b>Email Adress:</b> <input type="text" name="email" id="name" size="40" maxlength="60" /></p>

You cannot have two IDs with the same value, I suspect the second should be

id="email"
?

Apart from this, do your pages validate [validator.w3.org]?

Are you getting any PHP errors? Do you have full error_reporting On? ie. At the start of your script:

ini_set('display_errors','On'); 
error_reporting(E_ALL ¦ E_STRICT);

The output you are getting is like you have a mismatch of quotes or you are using single quotes to delimit the entire string?! But the code you have posted appears OK.

tottyovi

11:27 am on Jun 30, 2009 (gmt 0)

10+ Year Member



I know that I can't have 2 IDs with the same value...but the ID I putted after...so the code was first without "id".

In dreamweaver cs 4 I have some errors:

Notice: Undefined index: name in C:\wamp\www\php\handle_form.php on line 12
Notice: Undefined index: email in C:\wamp\www\php\handle_form.php on line 13
Notice: Undefined index: comments in C:\wamp\www\php\handle_form.php on line 14
Thank you, $name, for the following comments:
$comments

We will reply to you at $email.

I think all quotes are ok...entire the page source is up(on my first post)....so is the same

penders

12:24 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Notice: Undefined index: name in C:\wamp\www\php\handle_form.php on line 12

It does not appear that your FORM fields are being passed back to your handle_form.php script. What version of PHP are you using?

Try outputing the contents of $_REQUEST to see what it contains...

print_r($_REQUEST);

Strictly speaking you should be using the $_POST array instead of $_REQUEST, since it will be more secure, but $_REQUEST should still work.

Are you testing this within the dreamweaver environment? Or in a separate browser on the webserver? I would have expected different output if the later?!

tottyovi

2:31 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



I'm testing on dreamweaver and firefox, but I never had problems. My php versions is 5.2.9-2 (I installed wamp...so was all in one). In dreamweaver show me that error taht I mention before plus "Thank you.......". In firefox is showing me only the part with "Thank you, $name, ....."
I will try to put these 2 files on a different server, where I have another site ...but I guess that I must to configure the server and I don't....so...I'm stuck.

penders

3:17 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



...but I guess that I must to configure the server and I don't....so...I'm stuck.

You shouldn't have to configure the server to get this to work. This should work on any configuration, so there must be something fundamentally wrong somewhere.

As suggested above, what do you get if you output the contents of $_REQUEST ?

Does phpinfo() produce the expected output?

tottyovi

3:39 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



please be more specified...I'm beginner...how to output the contents of $_REQUEST?

jatar_k

3:42 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



like so would work

echo '<pre>';
print_r($_REQUEST);
echo '</pre>';

tottyovi

3:57 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



where I put this code?...

penders

4:38 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



where I put this code?...

At the point in your code where you are trying to access the $_REQUEST array in handle_form.php. Or you could put it immediately after the <body> tag - at the very top of your page.

ie.

<body> 
<?php
echo '<pre>';
print_r($_REQUEST);
echo '</pre>';
?>

tottyovi

5:36 pm on Jun 30, 2009 (gmt 0)

10+ Year Member



And I will let this code?

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comments = $_REQUEST['comments'];

penders

8:04 pm on Jun 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, you can still keep your existing code. This additional code is just to try and find out where the problem is.

tottyovi

6:36 am on Jul 1, 2009 (gmt 0)

10+ Year Member



Ok.
Here you have the output:
'; print_r($_REQUEST); echo ''; ?> Thank you, " . $name . ", for the following comments:
" . $comments . "

We will reply to you at " . $email . ".
"; ?>

The code source is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Handle form</title>
</head>

<body>
<?php
echo '<pre>';
print_r($_REQUEST);
echo '</pre>';
?>

<?php
//Creaza o forma prescurtata pentru datele din formular.

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$comments = $_REQUEST['comments'];
//Nefolosit eage, gender, submit

//Afiseaza informatiile transmise.

echo "<p>Thank you, <b>" . $name . "</b>, for the following comments:<br /><tt>" . $comments . "</tt></p><p>We will reply to you at <i>" . $email . "</i>.</p>";

?>
</body>
</html>

I feel like crazy

tottyovi

6:39 am on Jul 1, 2009 (gmt 0)

10+ Year Member



On my server (online server, a hosting server) show me this:
Array
(
[name] => ryhrtyh
[email] => tyhrt
[gender] => F
[age] => 0-29
[comments] => fghfgh
[submit] => Submit my information
[trafic_h] => 95d09a6l7516bf251cb42ec4fba526a1*1239540160*totuldesprebani.com*1246346340*1246376176*40
[__utma] => 1.3100110291912123400.1241260891.1241263684.1241504813.3
[__utmz] => 1.1241260891.1.1.utmcsr=(direct)¦utmccn=(direct)¦utmcmd=(none)
)

Thank you, ryhrtyh, for the following comments:
fghfgh

We will reply to you at tyhrt.

tottyovi

7:02 am on Jul 1, 2009 (gmt 0)

10+ Year Member



So, in conclusion, on my hosting server is working...now where is the problem on my php?

dreamcatcher

7:23 am on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You say you are using Wamp? Have you got your files in the correct place? ie, inside the www folder? And are you accessing your pages offline using [localhost?...]

www/form.html (http://localhost/form.html)
www/handle_form.php (http://localhost/handle_form.php)

dc

tottyovi

7:55 am on Jul 1, 2009 (gmt 0)

10+ Year Member



"You say you are using Wamp? Have you got your files in the correct place? ie, inside the www folder? And are you accessing your pages offline using [localhost?"...] YES, EXACTLY.
THE PATH IS C:\wamp\www\php\

Is not something about my settings or extensions? I repeat that I created others php files and everything was ok

penders

8:26 am on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



jatar_k: so then it looks like the php isn't getting parsed...

Yes, as jatar_k suggests in the 3rd post, the output you are getting is as if the PHP is not getting parsed at all! As if you are accessing your files outside of your webserver (as dreamcatcher suggests). Is your webserver (ie. Apache) running?

However, you say, "yes, other works...", which would imply PHP IS getting parsed in other files? And to get notice/warnings such as:

Notice: Undefined index: name in C:\wamp\www\php\handle_form.php on line 12
Notice: Undefined index: email in C:\wamp\www\php\handle_form.php on line 13
Notice: Undefined index: comments in C:\wamp\www\php\handle_form.php on line 14

...then the PHP must be getting parsed?! Although you say those 'errors' were within dreamweaver? Does dreamweaver have its own webserver?!

penders

8:32 am on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A simple test of your webserver/PHP... create a file called phpinfo.php with the following code in it (just 1 line):

<?php phpinfo(); ?>

Navigate to this file in your browser ie. "http://localhost/phpinfo.php" or wherever the file is located. What output do you get? If PHP/webserver is working then you should see several pages of PHP configuration settings.

(Delete this file when you are finished with it.)

tottyovi

10:23 am on Jul 1, 2009 (gmt 0)

10+ Year Member



Other PHP files is getting parsed, I'm sure for this.
I can see these errors when I'm using dreamweaver (on the Live view button)

I created this:<?php phpinfo(); ?>...and I sow a white page.
But on the [localhost...] I have a PHP menu ->on the Tools menu I have phpinfo(). When I click on this I can see several pages about PHP, extensions, etc.

tottyovi

10:26 am on Jul 1, 2009 (gmt 0)

10+ Year Member



On the Your Aliases menu->phpmyadmin(I click on this) ->

Welcome to phpMyAdmin

Error

MySQL said: Documentation
#1045 - Access denied for user 'root'@'localhost' (using password: NO)
phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

penders

11:24 am on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I created this:<?php phpinfo(); ?>...and I sow a white page.

If you see a white/blank page then the PHP is not being processed. What URL are you using to access this page (phpinfo.php) ?

But on the [localhost...] I have a PHP menu ->on the Tools menu I have phpinfo(). When I click on this I can see several pages about PHP, extensions, etc.

That sounds like the WAMP control panel? If this works, then your phpinfo.php should also work. As dreamcatcher suggests, it does sound like your files are in the wrong place, but other things you say seem to suggest they are OK?

When you view the PHPInfo (via the WAMP control panel) what does it give for the value of DOCUMENT_ROOT ?

tottyovi

11:27 am on Jul 1, 2009 (gmt 0)

10+ Year Member



DOCUMENT_ROOT C:/wamp/www/

penders

12:15 pm on Jul 1, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In that case, if you put the file in:
C:/wamp/www/phpinfo.php

Then you should access this file in the browser with:

http://localhost/phpinfo.php

But you get a blank page? Sorry if we appear to be repeating ourselves, but it would seem to be something very fundamental that is being missed here.

This 33 message thread spans 2 pages: 33