I can't take data out of database

+1 vincent van Duijnhoven · July 16, 2014
I am trying to connect to a database.
the connect part went without any problems but when i try to take data out of the database it doesn't work.

this is the code

    require 'connect.inc.php';

    $query = "SELECT * FROM `users` ";

    if ($query_run = mysql_query($query)){
        echo 'Query succes';
        echo mysql_error();

Post a Reply


Oldest  Newest  Rating
0 William Frost · July 18, 2014
@YuKusawa Ayoub  You can call me frost :)
+2 Darius Rapalis · July 18, 2014

it get the error no database found but if i run the connection script it says it is connected 

I assume that you haven't connected to database or trying to connect to database that doesn't exist
+2 YuKusawa Ayoub · July 18, 2014
Yeah , Mr.Frost , You're Right , I'm using too Mysqli , but He uses Mysql for that I answer him with mysql , it will Stop in future :) , So All Scripts With Mysql will Stops :p
+1 William Frost · July 18, 2014
Why you guys use mysql_something? Everybody is using mysqli_something which is better. Also if I am not wrong Zend(The guys who develop PHP) are you going to delete mysql_something in the near future.
+1 YuKusawa Ayoub · July 18, 2014
Change Ur Code , and make it Good like that :

    require 'connect.inc.php';

    $query = "SELECT * FROM `users` ";
     $query_run = mysql_query($query);
// After that , extart all informations u want
    $row = mysql_fetch_object($query_run);
echo 'username is '.$row->username.; // or something like that
why u used a condition O.o
or :

    require 'connect.inc.php';

    $query = "SELECT * FROM `users` ";
$query_run = mysql_query($query);
$num_rows = mysql_num_rows($query_run);
if ($num_rows > 0) {
    echo "there's some users";
}else {
  echo 'No users On database';
+1 Alan Johnson · July 17, 2014
Post the full code
+1 JOhaL jaTT · July 17, 2014
try this mate $result = "SELECT * FROM user";
mysql_query($result) or die (mysql_error());
mysql_query is a boolean key word so it will return either true or false means 1 or 0. if your query does work you will see query success else it will give you a error message.    
+2 Franz Schmidt · July 17, 2014
Could you please post your connect.inc.php?
+1 vincent van Duijnhoven · July 17, 2014
it get the error no database found but if i run the connection script it says it is connected and how works msqli?
+1 Alan Johnson · July 16, 2014

  1. Are you sure connecting is working?

  2. Are you sure you have a table called users?

If the answer to those is yes, post the error you are getting.

Also, you should look at using PDO or mysqli instead of the mysql_* functions.
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.