English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have two files I have stripped all the SQL off them to try and get the POST thing working. This is how the two files look

- user_input_form.php




Username:
Password:





Which works fine but when it goes to the other file

- user_out.php


$username = $_POST["username"]
$password = $_POST["password"]

echo '$username';
echo '$first_name';

?>

returns

Parse error: syntax error, unexpected T_VARIABLE in /home/zendurl/public_html/9/914840/php test/user_out.php on line 4

2007-09-01 10:21:30 · 4 answers · asked by jackkenyon1991 1 in Computers & Internet Programming & Design

4 answers

1. To debug your code for a $_POST, add the lines:
echo ("

");
print_r($_POST);
echo ("
");
This will print all the contents of your post, and, with the variables you use, would print something like:
array[]
user_name - thename
password - thepass
2. You pass "user_name" and "password"
You try to read "username" and "password":
user_name is not equal to user_name!

You final PhP:
$username = $_POST['user_name'];
// note underscore, single quotes and semi-colon at end.
$password = $_POST['password'];
// note semi-colon at end.
echo ("Username = " . $user_name . "
");
echo ("Password = " . $password . "
");
?>
Note that I use echo (" : this is a bit old fashion, but safe!
Good luck

2007-09-01 22:25:58 · answer #1 · answered by just "JR" 7 · 0 0

the parse error is caused by the fact that the two lines:

$username = $_POST["username"]
$password = $_POST["password"]

are missing the ; which you must have to terminate them.

Names of array variables (the bit in square brackets in $_POST for example) are usually single- rather than double-quoted, though i don't think this will cause any real problems.

As Graham99999 said, you are also trying to output two variables which don't exist ($username contains $_POST['username'], which itself does not exist), but this doesn't matter. php is very forgiving and will just assign null values to them for you.

Unfortunately, you are also using echo to output them, but you have put them in single quotes. Echo will output stuff in single quotes literally, so you will get "$username$password" as the output. Not what you are after, i think. If you want the contents of the variables, rather than the name you use echo either like this:

echo $variable;

or in double quotes, when it will interpret the results of variables (but not constants), like this:

echo "$variable";

Revise your code as follows:


$username = $_POST['user_name'];
$password = $_POST['password'];

echo "$username $password";

?>

and you will have something usable.

2007-09-01 10:54:59 · answer #2 · answered by Anonymous · 2 0

you've got the user name part named two different things e.g. the text box is called user_name but you look for whats in username, plus you try to output the users first name but you haven't declaired what the users first name is anywhere; you've only declaired the username and password.

plus you missed semi-colons on the user_out.php username and password declairtions.

- user_input_form.php




Username:
Password:





Which works fine but when it goes to the other file

- user_out.php


$username = $_POST["username"];
$password = $_POST["password"];

echo '$username';
echo '$password';

?>

try that, can't be borther to get my envrioment set up to test it, or try to remember php

2007-09-01 10:29:15 · answer #3 · answered by bet bet bet 3 · 0 0


$username = $_POST["username"];
$password = $_POST["password"];

echo $username;
echo $password;

?>

In your code, you are missing the semicolon at the end of the line.

Also, you are echoing a variable that hasn't been assigned a value ($first_name). I changed it to $password.

Copy and paste this code and try it.

2007-09-01 10:57:18 · answer #4 · answered by Albert L 3 · 0 0

fedest.com, questions and answers