Jump to content

Help for a n00b!


sam06

Recommended Posts

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.com
DB_NAME = samuelhale_free
DB_USER = samuelhale_free
And I know my password :D

It 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
Link to comment
https://forums.phpfreaks.com/topic/21097-help-for-a-n00b/
Share on other sites

[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.com
DB_NAME = samuelhale_free
DB_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.
Link to comment
https://forums.phpfreaks.com/topic/21097-help-for-a-n00b/#findComment-93712
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/21097-help-for-a-n00b/#findComment-93828
Share on other sites

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 this
function 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 use
db_connect();
//query here[/code]
Link to comment
https://forums.phpfreaks.com/topic/21097-help-for-a-n00b/#findComment-93970
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.