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);
?>
1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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
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);
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.