Page 1 of 1

Learning PHP - parase error help

Posted: Fri Feb 13, 2009 5:13 pm
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

Re: Learning PHP - parase error help

Posted: Fri Feb 13, 2009 5:21 pm
by bobocheez
nevermind
messed around with it some more
got it to work

Re: Learning PHP - parase error help

Posted: Fri Feb 13, 2009 6:26 pm
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.

Re: Learning PHP - parase error help

Posted: Fri Feb 13, 2009 7:28 pm
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.