Page 1 of 1

Help with a bit of code

Posted: Fri Apr 25, 2003 7:28 pm
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.

Posted: Fri Apr 25, 2003 8:29 pm
by patrikG
And the error is?

Posted: Fri Apr 25, 2003 8:32 pm
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

Posted: Fri Apr 25, 2003 8:43 pm
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.

Posted: Fri Apr 25, 2003 8:45 pm
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?

Posted: Fri Apr 25, 2003 8:50 pm
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

Posted: Fri Apr 25, 2003 8:59 pm
by patrikG
Oromian, is that really Maria Carrey?

Posted: Sat Apr 26, 2003 5:21 am
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