SitePoint Sponsor |
|
User Tag List
Results 1 to 24 of 24
Thread: Parse error
-
Sep 10, 2006, 21:12 #1
Parse error
I'm getting this message:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/consul12/public_html/phpmysql/chapter4/jokelist.php on line 36
PHP Code:echo '<p>' . $row['joketext'] . '</p>';
-
Sep 10, 2006, 21:36 #2
- Join Date
- Sep 2006
- Location
- Oregon
- Posts
- 113
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I would guess that you did not connect to MySQL correctly.
-
Sep 10, 2006, 21:51 #3
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
with parse errors, your mistake is often on the lines before the line reported. this is because the parser did not fail until the line reported.
so look a few lines before line 36.
if your text editor provides syntax highlighting for php, your mistake will usually be obvious, as often the colors will go haywire around where you made your mistake. if you dont have an editor that offers this, get one now. a good code editior is indispensable. one i recomend is notepad++
-
Sep 10, 2006, 22:00 #4
Yeah, I actually have Notepad2 for that stuff. I'm having a tough time finding the error in there, though.
-
Sep 10, 2006, 22:02 #5
Originally Posted by bobber205
-
Sep 10, 2006, 22:07 #6
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
this is not a mysql connection error. this is a parse error.
you can always post a bit more code if your having a tough time. post the code before line 36.
-
Sep 10, 2006, 22:18 #7
Does it matter that the server I'm transferring all of this to is Linux, and the server on my computer at home is Windows? Just kind of grasping at straws here...
-
Sep 10, 2006, 22:37 #8
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
different versions of php could cause a parse error in only 1 version, although this is not common.
i dont think you have the same version of the file on the working and non working server.
-
Sep 11, 2006, 01:09 #9
- Join Date
- Aug 2004
- Location
- Manchester UK
- Posts
- 13,807
- Mentioned
- 158 Post(s)
- Tagged
- 3 Thread(s)
Post some more code as clam suggested. It doesn't look like a connection error.
Mike Swiffin - Community Team Advisor
Only a woman can read between the lines of a one word answer.....
-
Sep 11, 2006, 01:43 #10
Try to print the 5 lines above 36 and below 36
-
Sep 11, 2006, 07:38 #11
Here they are, and thanks to everybody for taking a look at it:
PHP Code:$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
</blockquote>
</body>
</html>
-
Sep 11, 2006, 07:43 #12
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Doesn't look like the error is in there. Try posting the entire file.
-
Sep 11, 2006, 08:20 #13
When i take that same routine snippet and test it it works. The error is further up the script.
Are you using any echo<<<EOF 's
It could be that or even an extra } or {CDGcommerce
Project Devlopment, IT
-
Sep 11, 2006, 09:43 #14
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
my guess is you have an unclosed double quote "
but post more code.
-
Sep 11, 2006, 17:00 #15
Ok, here's the whole thing. What's weird is now I'm not connecting to the database at all. I haven't changed anything.
PHP Code:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Our List of Jokes</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
// Connect to the database server
$dbcnx = @mysql_connect('localhost' , 'username' , 'databasename' , 'password');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}
// Select the jokes database
if (!@mysql_select_db('joketable')) {
exit('<p>Unable to locate the joke ' .
'database at this time.</p>');
}
?>
<p>Here are all the jokes in our database:</p>
<blockquote>
<?php
// Request the text of all the jokes
$result = @mysql_query('SELECT joketext FROM joke');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
// Display the text of each joke in a paragraph
while ($row = mysql_fetch_array($result)) {
echo '<p>' . $row['joketext'] . '</p>';
}
?>
</blockquote>
</body>
</html>
-
Sep 11, 2006, 18:10 #16
- Join Date
- Sep 2006
- Location
- Oregon
- Posts
- 113
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You typically need a port number after the server name. Mine is
"localhost:8889".
That may be way you're not connecting.
-
Sep 11, 2006, 18:56 #17
I found somebody in our webhost's forums who helped me out, and we got it fixed. Thanks for your help though.
-
Sep 11, 2006, 20:42 #18
what was the issue?
-
Sep 11, 2006, 20:54 #19
I didn't have the correct database name at mysql_select_db. This was one of those "d-ohh" moments, that I seem to have a lot of since attempting to learn php/MySQL.
-
Sep 11, 2006, 21:06 #20
- Join Date
- Sep 2006
- Location
- Oregon
- Posts
- 113
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah ha!
I was right.
-
Sep 11, 2006, 21:09 #21
Originally Posted by bobber205
-
Sep 11, 2006, 22:21 #22
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
that doesnt make any sense if php was reporting a parse error.
weird...
-
Sep 12, 2006, 00:45 #23
- Join Date
- Jun 2004
- Location
- Copenhagen, Denmark
- Posts
- 6,157
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by clamcrusher
-
Sep 12, 2006, 20:30 #24
Can't say I disagree with you guys...All I know is that it's fixed now.
Bookmarks