Forum Moderators: coopster

Message Too Old, No Replies

php snytax help

php snytax help

         

meanweaver

11:31 pm on Jan 2, 2005 (gmt 0)

10+ Year Member



I am trying to write a simple php script for practice which pulls a row of data from a table in my database,
I am following an online tutorial which seemed to be going ok, however I am now getting a php error on all if statements, I have gone though everything and cant see what i am doing wrong, can anyone see anything obvious with the following code,

//connect to the database
$dbcnx=@mysql_connect('localhost','manleynet','password')
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>'); */

this is not the only error but the one i am having the most problem with.

Regards
Ian

coopster

11:50 pm on Jan 2, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




I am following an online tutorial

But have you tried the PHP Forum tutorial on the Basics of extracting data from MySQL using PHP [webmasterworld.com]? ;)

It seems you are forgetting to terminate your first statement with a semicolon and you also forgot to close your if control structure with a closing brace:

//connect to the database 
$dbcnx=@mysql_connect('localhost','manleynet','password');
if (!$dbcnx) {
exit('<p>Unable to connect to the database server at this time.</p>');
}

meanweaver

1:24 am on Jan 3, 2005 (gmt 0)

10+ Year Member



Thanks for that,
well that cleared that error up but have now hit another one, perhaps i will scrap tis and start again with this using the tutorial you pointed out, i dont know if i am just slow picking all this up but i find the syntax very hard to get the hang of with small things like where to put ' ect, I can read though simple scripts that extract data from a database but as i sit here right now i just cant see the day i will be able to write the stuff off the top of my head, perhaps it is me or has everyone felt like that at the start.

Thanks for your advice regards
Ian

coopster

1:10 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are not alone. A recent member asked the same question, When does the fog start to clear [webmasterworld.com]?

So hang in there, meanweaver ;)

mcibor

2:22 pm on Jan 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I htink the fog never starts to clear. On one day I received an error on line with finishing?>. There were colons everywhere, where should be. After an hour of search i fould out that there was an apostrophe just after starting <?PHP`
Horrible, horrible mistake!

Best wishes in learning PHP!