Tallal Hassan
Tallal Hassan

Reputation: 133

Whats wrong with my database connection file?

The output of code is :

Connected and SQL Problem

Which means that it connects but the desired databse i.e malala is not being selected.Please help?

  $con = mysqli_connect("localhost", "username", "password") or die("Connection Problem" . mysqli_connect_error($con));
  echo "Connected and ";
  $database = mysqli_select_db($con,malala) or die("SQL Problem".mysqli_connect_error($con));
  echo "Selected"; 

Upvotes: 0

Views: 53

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74232

Because, malala in ($con,malala) needs to be quoted. It's being treated as a constant.

I.e.:

($con, "malala")

Or place it inside

$con = mysqli_connect("localhost", "savehand_tallal", "&aBE+9NxZ6^c")

as

$con = mysqli_connect("localhost", "savehand_tallal", "&aBE+9NxZ6^c", "malala")

so you won't need to use

$database = mysqli_select_db($con,malala)...

Having used error reporting though, would have thrown you an undefined constant malala notice.

Reference for mysqli_connect():

Also make sure that the malala database was indeed created and doesn't hold any whitespace or foreign characters.

Upvotes: 2

Related Questions