PDA
Partners

View Full Version : Error


Steveo31
February 24th, 2004, 01:03 AM
I'm learnin PHP, so be nice :p

This is givin me an error I can't get around... could you take a look?
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

if(isset($name) && isset($address) && isset($comments)){
$name=$_POST['name'];
$address=$_POST['address'];
$comments=$_POST['comments'];
print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Name: $_GET['name']<br>
Email: $_GET['address']<br>
Comments: $_GET['comments']<br>
</td>
</tr>
</table>" or die(php_error());
}else{
print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Please fill out the form.\n
</td>
</tr>
</table>";
}
}
?>
<form action="<? $_SERVER['PHP_SELF'] ?> " method="post">
<p>
Name:&nbsp;&nbsp;<input type="text" name="name">
</p>
<p>
E-Mail:&nbsp;&nbsp;<input type="text" name="address">
</p>
<p>
Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></textarea>
</p>
<p>
<input type="submit" value="Submit">
</p>
</form>
</body>
</html>

Error:

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in c:\program files\easyphp1-7\www\tester.php on line 17


Thanks.

ZYV
February 24th, 2004, 06:05 AM
Here is the correct version:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

if(isset($name) && isset($address) && isset($comments)){
$name=$_POST['name'];
$address=$_POST['address'];
$comments=$_POST['comments'];
print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Name: ".$name."<br>
Email: ".$address."<br>
Comments: ".$comments."<br>
</td>
</tr>
</table>" or die(php_error());
}else{

print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Please fill out the form.\n
</td>
</tr>
</table>";

}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p>
Name:&nbsp;&nbsp;<input type="text" name="name">
</p>
<p>
E-Mail:&nbsp;&nbsp;<input type="text" name="address">
</p>
<p>
Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></text>
</p>
<p>
<input type="submit" value="Submit">
</p>
</form>
</body>
</html>

I didn't remember all the errors, there were lots of, but the main was

Name: $_GET['name']<br>
Email: $_GET['address']<br>
Comments: $_GET['comments']<br>


And one extra closing brace "}"

Hope that helps.

Steveo31
February 26th, 2004, 10:35 PM
Thanks for the help, and it makes sense, but the solution was:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php

if(!empty($_POST['name']) && !empty($_POST['address']) && !empty($_POST['comments'])){
$name=$_POST['name'];
$address=$_POST['address'];
$comments=$_POST['comments'];
print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Name: $name<br>
Email: $address<br>
Comments: $comments<br>
</td>
</tr>
</table>" or die(php_error());
}else{

print "<table width=\"100%\" height=\"30%\" cellpadding=\"0\" cellspacing=\"0\">
<tr>
<td>
Please fill out the form.\n
</td>
</tr>
</table>";

}
?>

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<p>
Name:&nbsp;&nbsp;<input type="text" name="name">
</p>
<p>
E-Mail:&nbsp;&nbsp;<input type="text" name="address">
</p>
<p>
Comments:&nbsp;&nbsp;<textarea cols="20" rows="10" name="comments"></textarea></text>
</p>
<p>
<input type="submit" value="Submit">
</p>
</form>
</body>
</html>

Thanks again :)

:beer:

ZYV
February 27th, 2004, 09:26 AM
Practically the same... Cool that you worked it out.

Steveo31
February 27th, 2004, 10:45 PM
Well, seeing as how no one else is really posting new threads, can you explain \n and \r? I hear they are supposed to be new lines and carriage returns, but I only get spaces in the echo()'d output.

ZYV
March 5th, 2004, 09:49 AM
Steveo31

can you explain \n and \r?

True, they are just new lines and carriage returns. But when you echo() them, take care to echo() "<pre>" (preformatted text) tag before, because otherwise browsers will just ignore them or consider like spaces.

Then, usually, we only use them in pair: "\r\n", most of *nix'es accept just "\n" as well, but to conform to the RFCs you should use only pairs.

kitty
September 1st, 2005, 04:13 AM
u can search for php manual u will find it alot any function u want,try php.net

Marshall
September 1st, 2005, 11:56 PM
u can search for php manual u will find it alot any function u want,try php.net
This post is over a year old so its safe to assume that ZYV's fixes worked out for him, no need to post and bring it back to the top.

edit just saw other posts - kitty are you even checking the date on the posts you and replying to? You are posting in posts a year after the last response....