PDA

View Full Version : simple unexpected $end question


mr_badger
04-19-2007, 09:54 PM
I have this piece of code that has an unexpected $end error, I know this will be something simple but I just need someone to tell me this once.

<?php



require("header.php");

$sql = "SELECT entries.*, categories.cat FROM entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1;";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
echo "<h2><a href='viewentry.php?id" . $row['id']
. "'>" . $row['subject'] .
"</a></h2><br />";
echo "<i>In <a href='viewcat.php?id" . $row['cat_id'] ."'>" . $row['cat'] .
"</a> - Posted on " . date("D jS F Y g.iA",
strtotime($row['dateposted'])) .
"</i>";

if(isset($_SESSION['USERNAME']) == TRUE) {
echo " [<a href='updateentry.php?id=" . $row['id'] . "'>edit</a]";
}
echo "<p>";
echo nl2br($row['body']);
echo "</p>";
echo "<p>";

$commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] .
"ORDER BY dateposted;";
$commresult= @mysql_query($commsql);
$numrows_comm = mysql_num_rows($commresult);
if($numrows_comm == 0) {
echo "<p>No Comments.</p>";
}
else {
echo "(<strong>" . $numrows_comm . "</strong>)comments : ";
$i = 1;
while($commrow = mysql_fetch_assoc($commresult)) {
echo "<a href='viewentry.php?id=" . $row['id'] . "#comment" . $i .
"'>" . $commrow['name'] . "</a> ";
$i++;
}
}
echo "</p>";
$prevsql = "SELECT entries.*, categories.cat FROM entries, categories
WHERE entries.cat_id = categories.id
ORDER BY dateposted DESC
LIMIT 1, 5;";
$prevresult = mysql_query($prevsql);
$numrows_prev = mysql_num_rows($prevresult);

if($numrows_prev == 0) {
echo "<p>No previous entries.</p>";
}
else {
echo "<ul>";
}
while($prevrow = mysql_fetch_assoc($prevresult)) {
}
echo "<li><a href='viewentry.php?id="
. $prevrow['id'] . "'>" . $prevrow ['subject]" . "</a></li>";




echo "</ul>";

?>

Thankyou for any help.

davidj
04-20-2007, 07:16 AM
did you hand code this or copy and paste it

please post the error your actually getting

davidj
04-20-2007, 07:19 AM
There is no $end var in the script you posted so that is not causing the error

mr_badger
04-20-2007, 01:11 PM
the error is saying:Parse error: parse error, unexpected $end in C:mydirectory on line 72 which is the very end of the code.

davidj
04-20-2007, 03:15 PM
this is incorrect...


echo "<li><a href='viewentry.php?id="
. $prevrow['id'] . "'>" . $prevrow ['subject]" . "</a></li>";



echo "</ul>";


replace with...


echo "<li><a href='viewentry.php?id="
. $prevrow['id'] . "'>" . $prevrow ['subject'] . "</a></li>";



echo "</ul>";


its a complete mess. Sort your indentation. It would be a nightmare supporting your applications.

mr_badger
04-20-2007, 04:05 PM
thankyou, I can't beleive I missed something so simple.

mr_badger
04-21-2007, 06:16 PM
its a complete mess. Sort your indentation. It would be a nightmare supporting your applications.Whats the best way to write the code?

davidj
04-21-2007, 06:25 PM
you have stuff like this...


echo "<li><a href='viewentry.php?id="
. $prevrow['id'] . "'>" . $prevrow ['subject]" . "</a></li>";



echo "</ul>";


why not just do this..

$stuff = "<li><a href='viewentry.php?id=".$prevrow['id'] . "'>".$prevrow ['subject]" . "</a></li></ul>";

you can now use $stuff anywhere you want

i think you are there with your IF statements...

i write them like this...


IF($condition==1){

do stuff

IF($condition==2){

do more stuff

}

}



always have the closing brace directly below the IF then you can follow it with your eye

and always indent your nested IF's

mr_badger
04-23-2007, 07:29 PM
I hate having to ask this again but I have another unexpected $end problem, I have looked and looked and even rewritten the code but I still get this problem, I get that the last time I missed putting a ' within brackets but I just can't figure this out, I think it's something to do with the $mail_body=<<<_MAIL_ as this is the point the code breaks down but I just need an explanation.

<?php

session_start();

require("config.php");

$db = mysql_connect($dbhost, $dbuser, $dbpassword);
mysql_select_db($dbdatabase, $db);

if($_POST['submit']) {
if($_POST['password1'] == $_POST['password2'] ) {
$checksql = "SELECT * FROM users WHERE username = '" . $_POST['username'] . "';";
$checkresult = mysql_query($checksql);
$checknumrows = mysql_num_rows($checkresult);

if($checknumrows == 1) {
header("Location: " . $config_basedir . "register.php?error=taken");
}
else {
for($i = 0; $i < 16; $i++) {
$randomstring .= chr(mt_rand(32,126));
}

$verifyurl = "http://127.0.0.1/sites/forums/verify.php";
$verifystring = urlencode($randomstring);
$verifyemail = urlencode($_POST['email']);
$validusername = $_POST['username'];

$sql = "INSERT INTO users(username, password, email, verifystring, active) VALUES('" . $_POST['username'] . "', '" . $_POST['password1']
. "', '" . $_POST['email'] . "', '" . addslashes($randomstring) . "', 0);";
mysql_query($sql);

$mail_body=<<<_MAIL_

Hi $validusername,
Please click on the following link to verify your new account:

$verifyurl?email=$verifyemail&verify=$verifystring

_MAIL_;

mail('{$_POST['email']}', $config_forumsname . " User verification", $mail_body);
require("header.php");
echo "A link has been emailed to the address you entered below. Please follow the link in the email to validate your account.";
}
else {
header("Location: " . $config_basedir . "register.php?error=pass");
}
else {
}
else {

require("header.php");
switch('{$_GET['error']}' {
case "pass":
echo "Passwords do not match";
break;

case "taken":
echo "Username taken, please use another";
break;

case "no":
echo "Incorrect login details";
break;
}

?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<h2>Register</h2>
To register on the <?php echo $config_forumsname; ?> forums, fill in the form below.

<form action="<?php echo $SCRIPT_NAME ?>" method="post">
<table>
<tr>
<td>Username</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password1"></td>
</tr>
<tr>
<td>Password (again)</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="submit" value="Register"></td>
</tr>
</table>
</form>

<?php
}
require("footer.php");

?>
</body>
</html>

davidj
04-23-2007, 08:30 PM
What is this doing?


$mail_body=<<<_MAIL_
Hi $validusername,
Please click on the following link to verify your new account:

$verifyurl?email=$verifyemail&verify=$verifystring

_MAIL_;

mr_badger
04-23-2007, 09:34 PM
this is the email to send to the user for verification.

davidj
04-23-2007, 09:41 PM
well not in this world its not

if your assigning a string to a variable shouldnt it be in quotes?

I dont understand the layout of the code why is everything on a seperate line? This adds to the confusion


$mail_body=<<<_MAIL_
Hi $validusername,
Please click on the following link to verify your new account:

$verifyurl?email=$verifyemail&verify=$verifystring

_MAIL_;


my version...

$mail_body="Hi $validusername, Please click on the following link to verify your new account:$verifyurl?email=$verifyemail&verify=$verifystring";

im guessing here but this is your first endevour into PHP and you have copied this from somewhere?

mr_badger
04-23-2007, 09:57 PM
I have a book on PHP and I'am going through the tutorials in the book, I write the code word for word as in the book but as you have seen I'am getting alot of errors so I really appreciate your help, PHP is something I want to learn but I know it will take time.

davidj
04-23-2007, 10:03 PM
if you want to learn and understand it as well then lets do this together properly

take some time to follow the following

http://www.dreamweaverclub.com/vtm/php-mysql-apache.php

oh.. Throw that friggin book away!