PDA

View Full Version : PHP Error



308holes
February 3rd, 2003, 02:36
Hello all im having a problem it saying i have a error on my code and i dont know what it is.... says line17.. Please help



//News.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Lemo News</TITLE>
<LINK REL=stylesheet HREF='ikonboard.css' TYPE='text/css'>
</HEAD>
<BODY BGCOLOR=49525D BACKGROUND="hardwired_bak.gif" LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<?php
require("VAR.php");
$LINK = mysql_connect($HOST,$USER,$PASSWORD);
$QUERY = "SELECT * from $DBTABLE";
$RESULT = mysql_db_query($DBNAME,$QUERY,$LINK);

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
<p>NAME:$ROW[NAME]</p>
<p>TIME:$ROW[TIME]</p>
<p>DATE:$ROW[DATE]</p>
<p>NEWS:$ROW[NEWS]</p>
}
mysql_close($LINK);
?>
</BODY>
</HTML>

//VAR.php
<?php
$HOST = "localhost";
$USER = "NAME";
$PASSWORD = "PW";
$DBNAME = "News";
$DBTABLE = "DBNews"
?>

hohoho
February 3rd, 2003, 07:36
use this:

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
echo "<p>NAME:$ROW[NAME]</p>
<p>TIME:$ROW[TIME]</p>
<p>DATE:$ROW[DATE]</p>
<p>NEWS:$ROW[NEWS]</p>";
}
mysql_close($LINK);

Cagez
February 3rd, 2003, 16:03
make sure you put quotes around the array names ($ROW['NAME']).

Salam
February 4th, 2003, 00:21
And also { and } : "<p>{$ROW['NAME']}</p>"

308holes
February 4th, 2003, 02:45
Ok i tried this and getting erros still



<?php
require("VAR.php");
$LINK = mysql_connect($HOST,$USER,$PASSWORD);
$QUERY = "SELECT * from $DBTABLE";
$RESULT = mysql_db_query($DBNAME,$QUERY,$LINK);

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
<p>NAME:{$ROW['NAME']}</p>
<p>TIME:{$ROW['TIME']}</p>
<p>DATE:{$ROW['DATE']}</p>
<p>NEWS:{$ROW['NEWS']}</p>
}
mysql_close($LINK);
?>

conkermaniac
February 4th, 2003, 03:09
You're still missing the "echo" in the while loop!

Cagez
February 4th, 2003, 11:24
Yes, you are still missing the echo, but if it still produces errors, it may be the data your trying to print --if the content in "news" contained quotations, then it will cause an error, so it might be best to use htmlspecialchars() to escape the spcial HTML that may be inside of the variables.

308holes
February 4th, 2003, 17:51
The Variables are all Formatted as Text and i get an error on the first p tag"<p>NAME:{$ROW['NAME']}</p>"



<?php
require("VAR.php");
$LINK = mysql_connect($HOST,$USER,$PASSWORD);
$QUERY = "SELECT * from $DBTABLE";
$RESULT = mysql_db_query($DBNAME,$QUERY,$LINK);

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
print(<p>NAME:$ROW['NAME']</p>);
print(<p>TIME:$ROW['TIME']</p>);
print(<p>DATE:$ROW['DATE']</p>);
print(<p>NEWS:$ROW['NEWS']</p>);
}
mysql_close($LINK);
?>


this is the data in the MySQL Database


Webmaster 12:30:15PM 01/31/2003 Hello This is a Test

Cagez
February 4th, 2003, 19:55
Now your not putting quotes ;)


print "<p>NAME:$ROW['NAME']</p>";
print "<p>TIME:$ROW['TIME']</p>";
print "<p>DATE:$ROW['DATE']</p>";
print "<p>NEWS:$ROW['NEWS']</p>";

308holes
February 5th, 2003, 02:28
Ok THis is the Error i get now


parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'


and the code im useing


<?php
require("VAR.php");
$LINK = mysql_connect($HOST,$USER,$PASSWORD);
$QUERY = "SELECT * from $DBTABLE";
$RESULT = mysql_db_query($DBNAME,$QUERY,$LINK);

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
print("<p>NAME:$ROW['NAME']</p>");
print("<p>TIME:$ROW['TIME']</p>");
print("<p>DATE:$ROW['DATE']</p>");
print("<p>NEWS:$ROW['NEWS']</p>");
}
mysql_close($LINK);
?>

spec
February 5th, 2003, 02:47
while($ROW = mysql_fetch_arry($RESULT))
replace with
while($ROW = mysql_fetch_array($RESULT))

308holes
February 5th, 2003, 02:56
parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING'

Cyber-Scripter
February 5th, 2003, 06:55
Couldn't you use this?


echo "<p>".$ROW['NAME']."</p>";
echo "<p>".$ROW['TIME']."</p>";
echo "<p>".$ROW['DATE']."</p>";
echo "<p>".$ROW['NEWS']."</p>";

Also, did you use capital letters when you made the row names? So it might be like this:


echo "<p>".$ROW['name']."</p>";
echo "<p>".$ROW['time]."</p>";
echo "<p>".$ROW['date']."</p>";
echo "<p>".$ROW['news']."</p>";

I no expert though, just a beginner.:cry2: :)

Cagez
February 5th, 2003, 07:57
Thats right Cyber-Scripter. 308holes , make sure you have the right variable name's and key's, $row['this'] is different from $ROW['THIS']...

Salam
February 5th, 2003, 13:40
Originally posted by 308holes
and the code im useing


<?php
require("VAR.php");
$LINK = mysql_connect($HOST,$USER,$PASSWORD);
$QUERY = "SELECT * from $DBTABLE";
$RESULT = mysql_db_query($DBNAME,$QUERY,$LINK);

while($ROW = mysql_fetch_arry($RESULT))
{
//Place News in HTML Fields
print("<p>NAME:$ROW['NAME']</p>");
print("<p>TIME:$ROW['TIME']</p>");
print("<p>DATE:$ROW['DATE']</p>");
print("<p>NEWS:$ROW['NEWS']</p>");
}
mysql_close($LINK);
?>


You forgot { and } :
print("<p>NAME:{$ROW['NAME']}</p>");

Cyber-Scripter
February 5th, 2003, 14:10
Could we please see the information that you put into PhpMyAdmin(I presume)? And Salam, why do you need curly brackets? I have never seen that method before...:confused:

Cagez
February 5th, 2003, 15:37
The curlies arn't really needed in this case, they're used to print more complex statements, like $array[$i][$j]. The current code should be fine without them, but its advised to use them for anything more then a simple $var.

spec
February 5th, 2003, 18:28
This is what I would like you to try:



<?php
$link_id = mysql_connect( 'localhost', $dbuser, $dbuserpass);
mysql_select_db($dbname, $link_id);

$query = "SELECT * from $dbtable";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_assoc($result))
{
//Place News in HTML Fields
'<p>NAME:' . $row['name'] . '</p>';
'<p>NAME:' . $row['time'] . '</p>';
'<p>NAME:' . $row['date'] . '</p>';
'<p>NAME:' . $row['news'] . '</p>';
}
mysql_close($link_id);
?>


Change what needs to be changed, but this will not fail without you getting a better error

308holes
February 5th, 2003, 18:30
This is what is in the Table


Name:Webmaster Time:12:30:15PM Date:01/31/2003 New:Hello
This is a Test
thier all in Text Format

Cagez
February 5th, 2003, 18:48
Have you tried the various echo'ing we have discussed so far 308holes?

And make sure your naming everything right, if you have your column named 'Name' then you have to get it with $row['Name'].

spec
February 5th, 2003, 18:51
308holes are you completely ignoring our suggestions.
If that is what your database is then your row[] variables are wrong. If you want us to help help yourself by taking out suggestions.

Cagez
February 5th, 2003, 19:05
I think you should post a screen shot of your table! :devious2:

Salam
February 5th, 2003, 20:04
Originally posted by Cyber-Scripter
... And Salam, why do you need curly brackets? I have never seen that method before...:confused:
This is because when you are writing "<p>NAME:$ROW['NAME']</p>" , PHP cant understand what is the variable name : $ROW or $ROW['NAME']</p> or ...
And when you write "<p>NAME:{$ROW['NAME']}</p>" , PHP knows $ROW is an array .
You can try , this code :

$ROW['NAME']="aa" ;
print("<p>NAME:$ROW['NAME']</p>");
will return an error :
parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ...
But ,

$ROW['NAME']="aa" ;
print("<p>NAME:{$ROW['NAME']}</p>");
returns NAME:aa .

308holes
February 6th, 2003, 02:23
i am taking you advice i tried it will all the examples you people have send and they arnt working