Help with a bit of code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Help with a bit of code

Post by nigma »

Hey, I get an error when I run this:

Code: Select all

<?php

	$dbConn = mysql_connect("localhost", "user", "pass");
	if (!$dbConn)
	&#123;
		echo("Failed to connect to MySQL server.");
		exit();
	&#125;

	if (!@mysql_select_db("user"))
	&#123;
		echo("Failed to select MySQL database..");
		exit();
	&#125;

	$q = "select * from users";
	$result = mysql_query($q);
	
	echo <<<BTABLE
	<table border="0" width=50%>
	<tr><th>User ID:</th><th>User Password:</th><th>Account Created:</th></tr>
	BTABLE;

	if (!$result)
	&#123;
		echo("Failed to select users from MySQL database.");
		exit();
	&#125;

	while ($row = mysql_fetch_array($result))
	&#123;
		echo '<tr><td>' . $row&#1111;"user_id"] . '</td><td>' . $row&#1111;"password"] . '</td><td>' . $row&#1111;"created"] . '</td>';
		echo("<td><a href="deleteUser.php?user_id=" . $row&#1111;"user_id"] . "">Delete User</a></td></tr>");
	&#125;

	echo <<<ETABLE
	</table>
	ETABLE;
?>
I am trying to familiarize myself with the MySQL functions, but obviously I haven't gotten to far.

Thanks for any help provided.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

And the error is?
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

I got it working, there was a problem with these sections:

echo <<<BTABLE
//code
BTABLE;

echo <<<ETABLE
//code
ETABLE;

I don't actually know why that was causing an error, that exact code worked in a diff script but not in this one.

Do you know if there is a search engine that will let you look up the php error and it will tell you what the problem is?

Thanks
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Do you know if there is a search engine that will let you look up the php error and it will tell you what the problem is?
Not meaning to be flippant or anything, but that search-engine is a programmer's brain.
User avatar
nigma
DevNet Resident
Posts: 1094
Joined: Sat Jan 25, 2003 1:49 am

Post by nigma »

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /Path/To/File.
So someone with a brain and some common sense who is new to php is supposed to be able to understand what this means?
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

nigma wrote:Do you know if there is a search engine that will let you look up the php error and it will tell you what the problem is?
The human brain is the one i recommend too. I can't give you a URL though...

:wink:


Hey i did find this helpful site that *might* help for this type of thing...

PHP Knowledgebase
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

Oromian, is that really Maria Carrey?
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

nigma wrote:I got it working, there was a problem with these sections:

echo <<<BTABLE
//code
BTABLE;

echo <<<ETABLE
//code
ETABLE;

I don't actually know why that was causing an error, that exact code worked in a diff script but not in this one.
When you are using here doc format (your <<<BTABLE ... BTABLE;) making a mistake can cause any number of different errors, have a read of this (especially the warning :wink: ):
http://uk.php.net/manual/en/language.ty ... ax.heredoc

Mac
Post Reply