-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,997
  • 5
  • 21
  • 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.
  • 22,983
  • 19
  • 69
  • 116
benscabbia
  • 17,592
  • 13
  • 51
  • 62
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.