No data to display

Instead of this:

$conn= mysqli_connect("","",""); 
	if(mysqli_connect_error()) { 

I think you should do this:

$conn= mysqli_connect("","",""); 
if (!$conn) { 
  echo "Could not connect : " . mysqli_connect_error();
  exit();
}

And, is there a problem if you switch between procedural and OO mysqli functions? You open the connection with procedural (mysqli_connect()), then you select the database using OO ($conn->select_db()). I don’t use mysqli myself, this seems inconsistent at best, and if it leads to the database not being selected, would explain why your query fails.

$conn= mysqli_connect(“”,“”,“”);
if(mysqli_connect_error()) {

i tried this same thing it is strange on live site i have an error but on localhost no

$_SESSION[“user_id”] =$email;
works an go on next page like session but if add
$_SESSION[“first_name”] =$first_name;
wont work

I don’t understand how it can possibly be storing the email in a session variable if you are still getting this warning, which means that the query has not worked.

Unless you do that code in another location, of course - $email has come from the form, not the database, so as long as you do that outside of the loop that retrieves the results from your query, it would work regardless of whether the query worked.

query on local works so how can get first name

Does the local user have a default database, where maybe the hosted one does not?

don’t understand

I questioned further up whether your switch from procedural mysqli_connect() to OOP $conn->select_db() might be causing it to not select the database properly. You could just add the default database into the connection as a fourth parameter, or use the procedural version of the function. I don’t even know if it causes a problem as I use PDO. But if your username for the localhost had a default database, and your user on the hosted server does not, then it might get around the problem, if there is one.

root is local on live is diffrent

Doesn’t seem as if there is a default database in any case. But have you checked that the permissions are the same, that your live user has permission to access the database and table?

OK, how about trying this. For this line:

$conn->select_db("databasename"); // whatever db name you select

use this instead:

if (!$conn->select_db("databasename")) { 
  echo "Could not select database";
  exit();
}

Then we can see if it’s selecting the database properly. Again, it’ll return false if there is a problem selecting the database, then it will be down to figuring out why the problem occurs.

$conn= mysqli_connect("","",""); 
	if(mysqli_connect_error()) { 
		die('Could not connect: ' . mysqli_connect_error());
	}

	if (!$conn->select_db("cars123")) { 
  echo "Could not select database";
  exit();
}``
 is said
Could not select database

OK, we’re getting somewhere. If you can’t select the database, then your query won’t work. Try

$conn = mysqli_connect("", "", "", "cars123"); // with your username etc. of course

and lose the $conn->select_db() section completely.

Could not select database

How is it still displaying that, when you have removed that code?

No. There shouldn’t be a problem unless you use prepared statements. I believe prepared statements require what created the connection. You can’t use the procedural connection with an OOP prepared statement. You’re going to produce an error. And vice versa. That’s why I strongly suggest consistency.

1 Like

OK, maybe I’m on the wrong track. Still, it does point to a problem in the OPs setup in that attempting to select the database is failing.

oooooooo i fixed

How?

my bad i used db name from local on live :relieved: