Learning PHP - parase error help

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
bobocheez
Forum Commoner
Posts: 25
Joined: Mon Oct 27, 2008 8:06 pm

Learning PHP - parase error help

Post by bobocheez »

Hey,
I'm watching some tutorials on PHP and the guy messed up

The die functions give a Parase error
How should they be setup?

Code: Select all

 
//OPENS CONNECTION TO MYSQL SERVER
$dbc = mysql_connect('localhost','user','pass');
if (!$dbc){
        die('Not connected' : . mysql_error());
        }
        
//SELECT DATABASE
$db_selected = mysql_select_db("n_users", $dbc);
if (!$db_selected);
{
    die ("cant connect : " . mysql_error());
    }
 
P.S. I typed it in just as the guy did
Changed it afterward, but could not figure out how to make it work.

Thanks
bobocheez
Forum Commoner
Posts: 25
Joined: Mon Oct 27, 2008 8:06 pm

Re: Learning PHP - parase error help

Post by bobocheez »

nevermind
messed around with it some more
got it to work
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Learning PHP - parase error help

Post by requinix »

bobocheez wrote:nevermind
messed around with it some more
got it to work
It's always nice to post the solution. If somebody gets to this thread through a search engine with the same problem then they'll know how to solve it too.

Line 5: the colon should be inside the string, not outside.
Line 10: remove the semicolon.
bobocheez
Forum Commoner
Posts: 25
Joined: Mon Oct 27, 2008 8:06 pm

Re: Learning PHP - parase error help

Post by bobocheez »

Sorry about that.

For the above code, just make sure that the colon
:
is inside the quotation marks, otherwise, it will be read as part of the php code, which it will not understand since it is not defined to do anything in php.

Anything in those quotation marks will appear as is on page if there is an error.
Post Reply