-2

I am using PhpStorm; when I execute my code, the browser shows me:

you have created case

test

Table 'test.users' doesn't exist

But the table users does exist? How do I fix this?

My php code looks like this:

<?php
define('dbuser','root');
define('dbpass','');
define('dbserver','localhost');
define('dbname','test');

$conn = mysqli_connect(dbserver,dbuser,dbpass,dbname);

if(!$conn){
    die('error connecting to database');
}

echo 'you have created case';
?>

<h1>test</h1>

<?php
$query = "SELECT * FROM users";
$result = $conn->query($query);
if (!$result) die($conn->error);
?>

And in my Microsoft SQL Server I have a database named test with table users with one user in it.

Community
  • 1
  • 1

1 Answers1

2

First you need to sort out the basics.

You seem to have your connection to the database but that is just like switching on the computer. Now you have to do the work.

So:

  1. Are you using MySql or SQL Server?

  2. You need to think/read a bit more. https://www.w3schools.com/php/php_mysql_intro.asp is a good place to start (if you are using MySQL!).

    Make a cup of coffee and just BROWSE the mySql section (don't try and understand). Keep hitting the NEXT button and then circle back to look at the bits you need to know.

  3. Have another try (experiment lots!)

  4. Re-edit your question with what you have learned if you are still having problems!

And that's it!

This is not really an answer but it should help you get there.

One last very important thing: edit the question to something useful if you can. Stack Overflow can be very harsh on new users but if you make the effort to correct this then I will certainly upvote you to help you get started on Stack Overflow and hopefully a couple of forgiving souls will help you get back to zero.

My rule of thumb: I never post until I have done at least 30 mins research. Annoyingly, then when I then write the question, nine times out of ten I find the answer as I am editing it so never get to ask my "useful" question.

Keep trying. This place is immensely helpful but you do need to make the effort to get the best from it.

Community
  • 1
  • 1
BeNice
  • 2,165
  • 2
  • 23
  • 38