-1

I have a file login.php to try to connect to my database. I put the file login.ph inside the server folder and started the server. Then i call the file in the browser and it shows a blank page. It does not respond even if i change the values of the database to an incorrect value. I don't know if the error is inside the code or if it is another problem. Thanks.

login.php:

<?php
$username = $_GET['fname'];
$password = $_GET['fpass'];
$con=mysqli_connect("localhost","user","pass","db");
// Check connection

if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$qz = "SELECT contact_id FROM contacts" ; 
$qz = str_replace("\'","",$qz); 
$result = mysqli_query($con,$qz);
while($row = mysqli_fetch_array($result))
  {
  echo $row['contact_id'];
  }
mysqli_close($con);
?>
Sandra G.
  • 119
  • 3
  • 16
  • 1
    adding `error_reporting(E_ALL); ini_set('display_errors', '1'); ` to the top of your script enables error display. It is very handy while writing your script. – Duane Lortie Feb 05 '17 at 00:05
  • I aded those lines but the page is still in blank. – Sandra G. Feb 05 '17 at 00:24
  • Well you need to put something like echo "Hi, I got here ".__LINE__; after the two lines Duane mentioned and see if you can see that to make sure you are actually running this file. Failing that, just make a dummy file with an echo message like above and see if anything is working. – TimBrownlaw Feb 05 '17 at 01:02
  • Just did that. And in Firefox the page still shows blank. The same file in chrome shows the text inside the file. I understand i need an interpreter for the php t work but i have the Xampp installed and running the Apache and MySQL. – Sandra G. Feb 05 '17 at 01:33
  • How are you browsing to this file? Like `http://localhost/` or something else? It sounds like it isn't getting ran as PHP, Any error logs that might be helpful? see http://stackoverflow.com/questions/3719549/where-does-phps-error-log-reside-in-xampp – Duane Lortie Feb 05 '17 at 08:42

2 Answers2

0

You must check $con variable that you have set with the result of the connection:

if (!$con) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}
lot
  • 1,434
  • 18
  • 23
0

Do you have web server (say apache) installed and running on your server? You have to. Then put your file on the web server folder (say /var/www/html) and test in the browser.