Page 1 of 1
what is the problem of T_VARIABLE ?
Posted: Wed Aug 13, 2003 11:08 am
by lancet2003
when I run the following code, there also shows
Parse error: parse error, unexpected T_VARIABLE in c:\inetpub\wwwroot\hidden.php on line 5
<HTML>
<HEAD></HEAD>
<BODY>
<? php
$Message1="Bugs Bunny"; THERE IS A PROBLEM HERE
$Message2="Homer Simson";
$Message3="Ren & Stimpy";
echo "<FORM method="get" action="text.php">;
echo "what price of car are you looking for":
echo "<SELECT name="Price";
echo "<OPTION> $Message1</OPTION>";
echo "<OPTION> $Message2</OPTION>";
echo "<OPTION>$Message3</OPTION>";
echo "</SELECT><br>";
echo"<input type=hidden name=hidden value='$Message1'>";
echo"<input type=hidden name=hidden value='$Message2'>";
echo"<input type=hidden name=hidden value='$Message3'>";
echo"<input type=submit>";
echo"</Form>"
?>
</BODY>
</HTML>
Posted: Wed Aug 13, 2003 11:54 am
by nigma
I recommend you read this tutorial on HTML:
http://www.w3schools.com/html/default.asp
Then read memorize this:
http://www.php.net/manual/en/language.b ... ax.phpmode
Here is code that should work for you:
Code: Select all
<? php
$Message1 = "Bugs Bunny";
$Message2 = "Homer Simson";
$Message3 = "Ren & Stimpy";
echo '<FORM method="get" action="text.php">';
echo "what price of car are you looking for":
echo '<SELECT name="Price">';
echo "<OPTION> $Message1</OPTION>";
echo "<OPTION> $Message2</OPTION>";
echo "<OPTION>$Message3</OPTION>";
echo "</SELECT><br>";
echo '<input type="hidden" name="hidden1" value="$Message1">';
echo '<input type="hidden" name="hidden2" value="$Message2">';
echo '<input type="hidden" name="hidden3" value="$Message3">';
echo '<input type="submit">';
echo "</Form>"
?>
To be even more efficient when outputting HTML I suggest you use echo's "here document" syntax:
http://us4.php.net/echo
Thanks, " ' " instead of " " "
Posted: Wed Aug 13, 2003 4:36 pm
by lancet2003
Hi:
When I embed the HTML code in PHP, I should use " ' " instead of " " ",
is that right?
Thanks
Posted: Wed Aug 13, 2003 4:40 pm
by JAM
Discussed just earlier in another thread...
http://www.devnetwork.net/forums/viewtopic.php?t=11728
Take a look at that, and check out McGruff's link at the bottom...
Posted: Wed Aug 13, 2003 4:42 pm
by JayBird
Thats what he is saying

)
You could also escape the double-quotes and do it your way
e.g
Code: Select all
echo "<input type="hidden" name="hidden1" value="$Message1">";
Mark
Why value of variables Message1.2.3 can not be transfered?
Posted: Wed Aug 13, 2003 5:24 pm
by lancet2003
Here is the hidden.php code, there is no problem in it now.
Code: Select all
<?php
<HTML>
<HEAD></HEAD>
<BODY>
<?php
$Message1 = "Bugs Bunny";
$Message2 = "Homer Simson";
$Message3 = "Ren & Stimpy";
echo '<FORM method="get" action="text.php">';
echo "what price of car are you looking for";
echo '<SELECT name="Price">';
echo "<OPTION> $Message1</OPTION>";
echo "<OPTION> $Message2</OPTION>";
echo "<OPTION>$Message3</OPTION>";
echo '</SELECT><br>';
echo '<input type="hidden" name="hidden1" value=$Message1>';
echo '<input type="hidden" name="hidden2" value="$Message2">';
echo '<input type="hidden" name="hidden3" value="$Message3">';
echo '<input type="submit">';
echo '</Form>';
?>
</BODY>
</HTML>
?>
and here is text.php code
Code: Select all
<?php
<HTML>
<HEAD></HEAD>
<BODY>
<?php
echo "the three optons were <br>";
echo "$hidden1<BR>";
echo "$hidden2<BR>";
echo "$hidden3<BR>";
echo "<BR> You selected:<BR>";
echo "$Price"
?>
</BODY>
</HTML>
?>
when I run, the outcome always shows like this
< the three optons were
$Message1
$Message2
$Message3
You selected:
Homer Simson
why the value of varible message1, message2, message3 can not be transfer?
Posted: Wed Aug 13, 2003 7:18 pm
by qartis
Replace the three <input type=hidden lines with:
Code: Select all
echo "<input type="hidden" name="hidden1" value="".$Message1."">";
echo "<input type="hidden" name="hidden2" value="".$Message2."">";
echo "<input type="hidden" name="hidden3" value="".$Message3."">";
Or
Code: Select all
echo '<input type="hidden" name="hidden1" value='.$Message1.'>';
echo '<input type="hidden" name="hidden2" value='.$Message2.'>';
echo '<input type="hidden" name="hidden3" value='.$Message3.'>';
Or
Code: Select all
echo "<input type='hidden' name='hidden1' value='$Message1'>";
echo "<input type='hidden' name='hidden2' value='$Message2'>";
echo "<input type='hidden' name='hidden3' value='$Message3'>";
Thanks
Posted: Wed Aug 13, 2003 7:53 pm
by lancet2003
Thanks, I will see the related recommended turoial to understand these 3 solutions.
Posted: Wed Aug 13, 2003 10:45 pm
by nigma
Lancet, you really shouldn't have "<head></head>" you should have the page title inside the head tags and such.
what is the differences of "" , '' and \"
Posted: Wed Aug 13, 2003 11:19 pm
by lancet2003
Thanks all.
and I run the qartis's code, everyghing is OK, BUt still confused.
Can someone tell me what is the differences of "" , '' and \" \"
or tell me where can I get the tutoril for this. I guess there is some understanding problem of embedding HTML in PHP, right?
See the following codes:
echo '<SELECT name="Price">';
echo "<OPTION> $Message1</OPTION>";
echo "<OPTION> $Message2</OPTION>";
echo "<OPTION>$Message3</OPTION>";
echo '<SELECT name="Price">';
echo "<OPTION> $Message1</OPTION>";
echo "<OPTION> $Message2</OPTION>";
echo "<OPTION>$Message3</OPTION>";
;
THe only differences is "" and '', but they all run Ok.
Posted: Thu Aug 14, 2003 5:30 am
by Coco
the differences are in how the php server reads it
if you have a string inside " " then the php server will resolve all variables inside it
if you have it in ' ' then it wont, it will just print the variable name
\" and '' are used to show said characters inside those strings
eg:
Code: Select all
$foo = 'variable';
echo "this is a $foo";
echo 'this is a $foo';
echo 'this is a ''$foo''';
echo this is a '$foo'';
//the best solution, to prevent confusion in strings, is to use '.' which basically adds strings together
//ie.
echo 'this is a ' . $foo;
//results:
this is a variable
this is a $foo
this is a '$foo'
parse error
this is a variable
i usually use the last one, because its much easier to read.
Also note that if you are using ' ' you dont have to use \" (just use ") and if you are using " " you dont need to use ''