I've just started to study PHP at university and we've been given 10 exercises to do without any real aid we just have to figure it out for ourselves but I can't figure out how to make this work.
I've got a php page with a html table inside that has 10 boxes, in box 5 I have to make a form that allows you to input a four digit integer number or a four letter string and store it in a variable "$x". A user will put the numbers/letters in a box and click on a button labelled "submit" in order to enter the number/letter into the variable.
I made a form from a tutorial in a blank php page as a test and it worked but when I put it inside the HTML code (which is inside the php) I get this error:
Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in Y:\xampp\htdocs\laboneformtest.php on line 33
Below is the code:
<tr>
<td><b>Rectangle 5: input field four digit integer number or four letter string and
store in variable x</b><br /><br />
"if (isset($_POST['name'])) $name = $_POST['name'];
else $name = "(Not Entered)";
echo "
Your name is: $name<br />
<form method="post" action="formtest.php">
What is your name?
<input type="text" name="name" />
<input type="submit" />
</form>
</td>
I realise the form isn't for variable $x yet I just wanted to get this working before I started on that.
PHP code blocks must be delimited with <?php
and ?>
(if you've got short_tags turned on, <?
will work as well.
There is no such thing as a PHP script - there are only files that have PHP code blocks within them, and <?PHP ?>
is how you tell the PHP interpreter where it should start executing instead of just outputting.
<?php
if (isset($_POST['name'])) {
$name = $_POST[\"name"\];
} else {
$name = '(Not Entered)';
}
echo "Your name is: $name<br />";
?>
<form>etc......</form>
<?php
if( $_POST['name'] && $_POST['name'] != ""){
$name = urldecode( $_POST['name'] );
}else{
$name = "not set";
}
?>
<table>
<tr>
<td>
<?=$name?>
</td>
</tr>
</table>
<form here>