Jump to content


Photo

Help for a n00b!


  • Please log in to reply
4 replies to this topic

#1 sam06

sam06
  • Members
  • PipPipPip
  • Advanced Member
  • 71 posts

Posted 17 September 2006 - 09:24 PM

Hi there,
I am stuck on a bit of code :D
$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
And I know my password :D

It seems logical, but when I put in
$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);
I get

Parse error: parse error, unexpected '@' in /home/freehost/t35.com/s/a/sam06/reward/utils.php on line 12

(line 12 being the second line of code I gave you)

Thanks,
Sam

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 17 September 2006 - 10:41 PM

Quote your string literals!
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 tistaharahap

tistaharahap
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 17 September 2006 - 10:55 PM

$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


Should have that easily forgettable Dollar ($) sign for your varibles right?

And for the question u asked, should use quotes with strings.

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 18 September 2006 - 06:37 AM

And for the question u asked, should use quotes with strings.


Yes. Always 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.

#5 Guardian2006

Guardian2006
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 18 September 2006 - 02:20 PM

If I'm not mistaken, you are using constants not strings for the connection data.
If thats the case, it would be more like;
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





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users