0

When I run the script below on my browser all that prints out is 0: If I erase MySQL_errno I get nothing. How would I get a more detailed error?

 <?php
  $link = mysql_connect("192...", "root", "");
  mysql_select_db("visitors_tables");

  echo mysql_errno($link) . ": " . mysql_error($link). "\n";
  echo mysql_error();
   $query = "SELECT * FROM visitors";
  $result = mysql_query($query);
  while ($line = mysql_fetch_array($result))
  {
     foreach ($line as $value)
       {
     print "$value\n";
  }
  }
mysql_close($link);
?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Aaron
  • 4,380
  • 19
  • 85
  • 141
  • 1
    You can start by not using the `mysql_*()` functions in your script. http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – WWW Feb 20 '14 at 15:48

2 Answers2

2

You aren't getting an error. But since mysql_errno() and mysql_error() is in no condition, it gets echoed anyway.

You can do it like this:

function showError($link) {
    return mysql_errno($link).': '.mysql_error($link);
}

$link = mysql_connect("192...", "root", "") or die(showError($link));
mysql_select_db("visitors_tables") or die(showError($link));
//etc.
$result = mysql_query($query) or die(showError($link));

or ...; only gets called when there actually is an error.

kero
  • 10,647
  • 5
  • 41
  • 51
  • 1
    Thanks, I needed to test that my script is ok. It looks like the error is in my android code. On to the next problem – Aaron Feb 20 '14 at 16:06
0

try using the below code. & insert the column_name you want to fetch at echo $line['column_name']

<?php
  $link = mysql_connect("192...", "root", "");
  if($link){
    mysql_select_db("visitors_tables");
  }
  $query = "SELECT * FROM visitors";
  $result = mysql_query($query);
  while ($line = mysql_fetch_array($result)){
    echo $line['column_name']
  }
mysql_close($link);
?>
Akhil Sidharth
  • 746
  • 1
  • 6
  • 16