Empty php variables? Help...

ld13

Honorary Master
Joined
Oct 28, 2005
Messages
13,923
Reaction score
2,473
Location
Stellenbosch
I'm having a problem with a FORM of mine that does not want to work properly. Fine, does not want to work AT ALL. I've been sitting for 4 hours with this [-]stupid[/-] piece of code but no luck :o I'm getting desperate - I must be missing something (big) :o Seems like no info gets passed on properly? Please Help. Any help will be appreciated...

Live Demo of how it does not work lol :p

index.html
PHP:
<html>
<head><title>Untitled 2</title></head>
<body>
<form action=test.php method="post" target="_self" enctype="text/plain" name="hi">
NAME:<input type="text" name="name">
EMAIL:<input type="text" name="email">
<input type="submit" value="Press Me" name="hi">
</form>
</body>
</html>

test.php
PHP:
<?php
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$name = addslashes($_POST['name']);
@$email = addslashes($_POST['email']);
echo("OK");
echo($name);
echo($email);
echo("END");
?>
 
K I've never done PHP, but I just looked at a quick 5min tutorial, give this a try, heh :p (if you're willing)

index.html:
HTML:
<html>
<head><title>Untitled 2</title></head>
<body>
<form action=test.php method="post" target="test.php">
NAME:<input type="text" name="name">
EMAIL:<input type="text" name="email">
<input type="submit" value="Press Me">
</form>
</body>
</html>

test.php:
PHP:
<html><body>
<?php
$name = $_POST['name'];
$email = $_POST['email'];

echo "OK";
echo $name;
echo $email;
echo "END";

?>
</body></html>
 
Meh, I would tidy up the whole script for you but I'm really tired (only 5 hours slepp lst night). The action attribute in your form tag needs to be encased with inverted commas.

Therefore index.html should look like this:

PHP:
<html>
<head><title>Untitled 2</title></head>
<body>
<form action="test.php" method="post" target="_self" enctype="text/plain" name="hi">
NAME:<input type="text" name="name">
EMAIL:<input type="text" name="email">
<input type="submit" value="Press Me" name="hi">
</form>
</body>
</html>
 
Changing "text/plain" to "text/html" makes the script work
 
K I've never done PHP, but I just looked at a quick 5min tutorial, give this a try, heh :p (if you're willing)

I was willing to try just about anything, was just about to try it when I continued reading... Thx for the effort ;)

Have you tried something like Jotform or these two?
http://www.icebrrg.com/
http://wufoo.com/
If it's a simple form you need, I'm sure doing it through those will be the best, you can just paste the code in the file as needed ;)

Prefer keeping the processing on my server, and I also prefer learning from my own mistakes - like now :o

Thx ;)

Meh, I would tidy up the whole script for you but I'm really tired (only 5 hours slepp lst night). The action attribute in your form tag needs to be encased with inverted commas.

I had 4 hours of sleep, must be why I was making such stupid mistakes.

Changing "text/plain" to "text/html" makes the script work

Works like a charm. Do not know how that piece of code crept in. I love you :D

Thank you to everybody for their efforts. /me the n00b have learned something new today! :cool:
 
Pleasure ;)

You could even leave it out... ?

http://htmlhelp.com/reference/html40/forms/form.html

The ENCTYPE attribute specifies the content type used in submitting the form, and defaults to application/x-www-form-urlencoded. This content type results in name/value pairs sent to the server as name1=value1&name2=value2... with space characters replaced by "+" and reserved characters (like "#") replaced by "%HH" where HH is the ASCII code of the character in hexadecimal. Line breaks are encoded as "%0D%0A"--a carriage return followed by a line feed.

Authors should generally only use a different ENCTYPE when the form includes a TYPE=file INPUT element, in which case the ENCTYPE should be multipart/form-data and the METHOD must be post. The format of multipart/form-data requests is given in RFC 2388.
 
Top
Sign up to the MyBroadband newsletter
X