trying to connect to database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

trying to connect to database

Post by gaogier »

Parse error: parse error, unexpected T_LOGICAL_OR in /home/gaming/mysql_connect1.php on line 4

thats the error

heres the code

Code: Select all

<?php

$dbcnx = mysql_connect("localhost", "gaming_phpbb1", "password");
  or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("gaming_phpbb1");

function escape_data1 ($data){
	global $dbh;
	if (ini_get('magic_quotes_gpc')){
		$data = stripslashes($data);
	}
	return mysql_real_escape_string (trim ($data), $dbh);
}

?>
where have i gone wrong?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Code: Select all

<?php

$dbcnx = mysql_connect("localhost", "gaming_phpbb1", "password")
  or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("gaming_phpbb1");

function escape_data1 ($data){
   global $dbh;
   if (ini_get('magic_quotes_gpc')){
      $data = stripslashes($data);
   }
   return mysql_real_escape_string (trim ($data), $dbh);
}

?>
There was an extra semicolon in your mysql_connect statement.

See if that works.
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

now its this error

Warning: mysql_connect(): Access denied for user: 'gaming_phpbb1@localhost' (Using password: YES) in /home/gaming/mysql_connect1.php on line 3
I cannot connect to the database because: Access denied for user: 'gaming_phpbb1@localhost' (Using password: YES)
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Make sure you have the right username and password for your database. I hope your password is not password but if it's not don't post. I think I might have done that once.... :oops:
gaogier
Forum Contributor
Posts: 391
Joined: Wed Mar 02, 2005 1:02 pm
Location: Portsmouth, UK
Contact:

Post by gaogier »

i changed it, to password so i can show you guys

i addded a new user to it, and it now works thanks
Post Reply