...

View Full Version : I am having serious problems with variables. Please Help!



l3vi
03-11-2003, 01:09 AM
I am just trying to do something as simple as passing a password to the next page, and it will not work. I am a beginner with php, and the most I can actually do is the print() function... here is the code for form.html


<html>
<head>
<title>HTML Form</Title>
</Head>
<Body>

<form action="HandleForm.php" Method=GET>
Password <input type=TEXT Name="Pass"><br>
<input type=SUBMIT name="SUBMIT">
</form>

</Body>
</HTML>

And here is the code for HandleForm.php:


<?php
print "Your password was $Pass<br>";
?>

Could anybody tell me what I am doing wrong?????? Please?? Thanks for n e hlp in advance!!:thumbsup: :thumbsup:
Oh yeah, this is the error I keep getting:
Dumb Notice:
Notice: Undefined variable: Pass in c:\program files\apache group\apache\htdocs\l3vi\handleform.php on line 2

x_goose_x
03-11-2003, 01:23 AM
print "Your password was $_GET['Pass']<br>";

l3vi
03-11-2003, 02:28 AM
??? :confused: That still doesnt work.:confused:

Jason
03-11-2003, 02:31 AM
use $_POST['pass']; instead


Jason

l3vi
03-11-2003, 02:57 AM
Still doesnt work. It says:
Notice: Undefined variable: _Post in c:\program files\apache group\apache\htdocs\l3vi\handleform.php on line 2
Your password was

Jason
03-11-2003, 03:13 AM
<?php
echo "<html><head><title>HTML Form</Title></Head><Body>";
?>
<form action="HandleForm.php" Method="post">

<?php
echo "Password ";
echo ("<input type=TEXT Name="Pass"><br>";
?>

<SCRIPT LANGUAGE="JavaScript">
document.writeln ( '<input type=SUBMIT name="SUBMIT">');
</SCRIPT>
</form>

<?php
if (count($_POST > 0)){
$pass = $_POST['Pass'];
echo "here is your password ". $pass;
}
?>


</Body>
</HTML>


that should work. Its uses alot of php and some JS. if you can't see anything for the $_POST then try using var_dump($_POST); cause that will display the ARRAY that it creates.

Hope that helps.


Jason

l3vi
03-11-2003, 03:32 AM
Never Mind. I didnt think It would be that complicated just to pass one var to another page. Is it suppost to be that complicated??? cuz if it is, I really am just going to skip learning PHP.

Jesh
03-11-2003, 07:43 AM
Either your host sucks or your computer sucks, or *cough* *cough* somebody *cough* *cough* sucks.

Just kiddin :D

Try http://www.firepages.com.au and install it on your computer.

Even a MONKEY can learn PHP.

HAHAHAHA

BYE

firepages
03-11-2003, 05:57 PM
if $_POST['Pass'] does not work (assuming method="post") then try $HTTP_POST_VARS['Pass'];

if so tell your host to upgrade to PHP >=4.1 ASAP

if method="get" then use $_GET['Pass'] OR $HTTP_GET_VARS['Pass']

just to confuse you can also use $_REQUEST['Pass'] , which will pick up any POST , GET or COOKIE vars.



a foolproof versionof your original code would be...



<html>
<head>
<title>HTML Form</Title>
</Head>
<Body>

<form action="HandleForm.php" Method=GET>
Password <input type="TEXT" Name="Pass"><br>
<input type="SUBMIT" name="SUBMIT">
</form>

</Body>
</HTML>

--------------------------------------------------------------------------------

HandleForm.php:


<?php
print "has to work al versions ! >> Your password was ".$HTTP_GET_VARS['Pass']."<br>";

print "only on PHP>=4.1 ! >> Your password was ".$_GET['Pass']."<br>";

print "again only on PHP>=4.1 ! >> Your password was ".$_REQUEST['Pass']."<br>";

print "use braces to stop errors {} Your password was {$_GET['Pass']}<br>";

?>


I know there is a lot of choice there which can be confusing at first - but once you have PHP>=4.1 then you will quickly get used to using $_POST,$_GET,$_COOKIE etc .

whilst we are here :)

$_GET['Pass'];
and
$_GET[Pass];
and
$_GET['pass'];
are potentially 3 different variables ! - always quote your variable names unless you intend otherwise & remember variables are case sensitive.

this does cause problems when utilisising the variables though , eg
mysql_query("SELECT * FROM $table WHERE field=$_POST['field']");
will cause an error , using braces however will stop the error.
mysql_query("SELECT * FROM $table WHERE field={$_POST['field']}");

l3vi
03-12-2003, 03:43 AM
Originally posted by Jesh or *cough* *cough* somebody *cough* *cough* sucks.
[/B]
lol. I think that would b true. Thanx a BUNCH 4 all the hlp!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!:thumbsup: :)
btw, have u noticed that when u highlight the :) its not a happy face n e more? Its a poor little sad face...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum