-3
 < ?php
     $connection = mysql_connect(localhost","user","password") or die ("Couldn't connect to the server!");
     mysql_select_db("users", $connection) or die ("Couldn't connect to the database!");

I used the above code above to try and connect to my database but keep getting an error in line 2 where mysql_connect(localhost)---- I've typed in my localhost name correctly why won't it work?

please help this is my first day ever dealing with php and databases. thanks in advance.

Kypros
  • 2,999
  • 5
  • 20
  • 27

2 Answers2

0

Missing a quote in localhost:

$connection = mysql_connect("localhost","user","password") or die ("Couldn't connect to the server!");
I wrestled a bear once.
  • 21,988
  • 17
  • 67
  • 115
benscabbia
  • 16,476
  • 12
  • 45
  • 60
0

The correct way to do it is:

<?php
$connexion = mysql_connect("localhost", "user", "password")
    or die("Couldn't connect to the database! : " . mysql_error());
mysql_close($connexion);
?>

Nota Bene:

Rather use mysqli_ or PDO. What you are using here is deprecacted for security reasons.