Page 1 of 1

need help with a Simple news driven sites

Posted: Mon Sep 16, 2002 7:21 am
by prib
I am new to PHP/MYSQL so decieded to follow 1 of the tuorials. i worked through the tutorial and uploaded the files but unfortunatly it didnt work and just delivered the below error msg

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/dataEPHE/news.php on line 17

so i decieded to go and look at line 17 in the php file but it was blank.

i would really appreciate if some 1 could suggest what i may have done wrong or look over the code i have to c how i could get it to work

Posted: Mon Sep 16, 2002 7:24 am
by twigletmac
If you post lines 1-17 then we'll be able to offer suggestions on how to fix the error. Parse errors can often occur on a line above that mentioned in the error message.

Mac

code

Posted: Mon Sep 16, 2002 7:28 am
by prib
<html>
<title>test</title>
</head>
<body>

<?php
$db=mysql_connect("localhost","username","password") or die ("cant connect");
mysql_select_db("database",$db) or die ("cant change");
$news=mysql_query("select * from news ORDER BY date DESC LIMIT 8") or die ("cant get em");
while($rows=mysql_fetch_array($news)){
$date=date("F d, Y H:i ",$rows["date"]);
$author=$rows["author"];
$number="100%";
printf("<table cellpadding=2 cellspacing=0 border=0 width=%s>\n",$number);
echo "<td bgcolor=#496CB1 class='first'><b>$title</b></td>\n";
echo "<td align=right bgcolor=#496CB1 class='first'>$date</td><tr>\n";
echo "<td colspan=2><i>by <A href=\\"mailto:$email\\">$author</a></i>

$content</td></table><p>\n";
}

while($rows=mysql_fetch_array($news)){
$date=date("F d, Y H:i ",$rows["date"]);
$author=$rows["author"];
$number="100%";
printf("<table cellpadding=2 cellspacing=0 border=0 width=%s>\n",$number);
echo "<td bgcolor=#496CB1 class='first'><b>$title</b></td>\n";
echo "<td align=right bgcolor=#496CB1 class='first'>$date</td><tr>\n";
echo "<td colspan=2><i>by <A href=\\"mailto:$email\\">$author</a></i>
$content</td></table><p>\n";
}

?>

</body>
</html>

ok it is only a short document so i have posted it all

Posted: Mon Sep 16, 2002 7:42 am
by twigletmac
The problem is occuring because of the

Code: Select all

A href=&quote;mailto:$email&quote;&gt;
bit, if you change that to:

Code: Select all

A href="mailto:$email"&gt;
it should get rid of the parse error.

I think that you probably only need one while loop as well, so delete the second:

Code: Select all

while($rows=mysql_fetch_array($news)){ 
$date=date("F d, Y H:i ",$rows&#1111;"date"]); 
$author=$rows&#1111;"author"]; 
$number="100%"; 
printf("&lt;table cellpadding=2 cellspacing=0 border=0 width=%s&gt;\n",$number); 
echo "&lt;td bgcolor=#496CB1 class='first'&gt;&lt;b&gt;$title&lt;/b&gt;&lt;/td&gt;\n"; 
echo "&lt;td align=right bgcolor=#496CB1 class='first'&gt;$date&lt;/td&gt;&lt;tr&gt;\n"; 
echo "&lt;td colspan=2&gt;&lt;i&gt;by &lt;A href=&quote;mailto:$email&quote;&gt;$author&lt;/a&gt;&lt;/i&gt; 
$content&lt;/td&gt;&lt;/table&gt;&lt;p&gt;\n"; 
}
Mac

Posted: Mon Sep 16, 2002 8:13 am
by prib
the below error msg is still occuring when i veiw the page

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home/www/dataEPHE/news.php on line 17

i have changed what u have suggest and the code that i am now using looks like this

<html>
<title>test</title>
</head>
<body>

<?php
$db=mysql_connect("localhost","username","password") or die ("cant connect");
mysql_select_db("database",$db) or die ("cant change");
$news=mysql_query("select * from news ORDER BY date DESC LIMIT 8") or die ("cant get em");
while($rows=mysql_fetch_array($news)){
$date=date("F d, Y H:i ",$rows["date"]);
$author=$rows["author"];
$number="100%";
printf("<table cellpadding=2 cellspacing=0 border=0 width=%s>\n",$number);
echo "<td bgcolor=#496CB1 class='first'><b>$title</b></td>\n";
echo "<td align=right bgcolor=#496CB1 class='first'>$date</td><tr>\n";
echo "<td colspan=2><i>by <A href=\\"mailto:$email\">$author</a></i>

$content</td></table><p>\n";
}


?>

</body>
</html>

is this what u meant for me 2 do? if so can u think of ne other reasons i may be having this problem

thx for your help

Posted: Mon Sep 16, 2002 8:16 am
by twigletmac
You have to change this:

Code: Select all

<A href=&quote;mailto:$email">
to this:

Code: Select all

<A href="mailto:$email">
note that there is only one backslash (\) each time.

Mac

Posted: Mon Sep 16, 2002 8:30 am
by prib
Thx alot for your help