sam06 Posted September 17, 2006 Share Posted September 17, 2006 Hi there,I am stuck on a bit of code :D[code]$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ("Could not connect to database. Try later<BR>"); @mysql_select_db(DB_NAME, $link);[/code]DB_HOST = db5.awardspace.comDB_NAME = samuelhale_freeDB_USER = samuelhale_freeAnd I know my password :DIt seems logical, but when I put in [code]$link = mysql_connect (db5.awardspace.com/, samuelhale_free, PASSWORD) or die ("Could not connect to database. Try later<BR>"); @mysql_select_db(samuelhale_free, $link);[/code]I get[quote]Parse error: parse error, unexpected '@' in /home/freehost/t35.com/s/a/sam06/reward/utils.php on line 12[/quote](line 12 being the second line of code I gave you)Thanks,Sam Quote Link to comment Share on other sites More sharing options...
fenway Posted September 17, 2006 Share Posted September 17, 2006 Quote your string literals! Quote Link to comment Share on other sites More sharing options...
tistaharahap Posted September 17, 2006 Share Posted September 17, 2006 [quote]$link = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) or die ("Could not connect to database. Try later<BR>"); @mysql_select_db(DB_NAME, $link);DB_HOST = db5.awardspace.comDB_NAME = samuelhale_freeDB_USER = samuelhale_free[/quote]Should have that easily forgettable Dollar ($) sign for your varibles right?And for the question u asked, should use quotes with strings. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted September 18, 2006 Share Posted September 18, 2006 [quote author=tistaharahap link=topic=108431.msg436253#msg436253 date=1158533742]And for the question u asked, should use quotes with strings.[/quote]Yes. [i]Always[/i] put quotes around strings! The only place where they are optional are with integers and floats. If you have a boolean then it shouldn't. Quote Link to comment Share on other sites More sharing options...
Guardian2006 Posted September 18, 2006 Share Posted September 18, 2006 If I'm not mistaken, you are using constants not strings for the connection data.If thats the case, it would be more like;[code]define ('DB_HOST','db5.awardspace.com');define ('DB_NAME','samuelhale_free');define ('DB_USER','samuelhale_free');define ('DB_PASSWORD','whatever');//You can then declare a function to connect to the DB like thisfunction db_connect(){static $connected;if ($connected)return;$connected = true;mysql_connect(DB_HOST, USER, DB_PASSWORD) or error_msg ("User or password incorrect"); mysql_select_db(DB_NAME) or error_msg ("could not locate database");}// To run a queryy just usedb_connect();//query here[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.