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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.