0

I'm trying to teach myself Apache, php, javascript, and mysql from scratch (oh, and phpmyadmin). I'm having problem with getting php to display query results. I've tried more or less straight copying code from a couple different youtube tutorials, but nothing seems to work. I keep getting completely blank webpages. No error messages, no warnings, it's literally a completely blank webpage.

I'm using Apache 2.2.22, php 5.3.10, mysql version 5.5.35-0ubuntu0.12.04.2, and I'm running Ubuntu 12.04. I'll include the code below. I've got one file named infoQuery.php and another named connect.php. They're both in /var/www. This isn't open to the internet, this is just being done on a local virtual machine as a proof of concept before I try a more ambitious project on a hosted server.

connect.php

 <?php

         $dbhost = 'localhost';
         $dbuser = 'root';
         $dbpwd  = '****';

         $db     = 'nameEmail';

         $conn    = mysql_connect($dbhost, $dbuser, $dbpwd);
         mysql_select_db($db);

 ?>

infoQuery.php

<?php
        # I've also tried "include 'connect.php';"
        include './connect.php';

        $query = "SELECT * FROM nameAndEmail";
        $result= "mysql_query($query)";

        while($person = mysql_fetch_array(result)){

          echo "<h3>" . $person['name'] . "</h3>";
        }

?>
John Conde
  • 217,595
  • 99
  • 455
  • 496
Tim Bauer
  • 11
  • 5

2 Answers2

1

Get rid of the quotes around mysql_query(). They make it a string and is thus not executed as PHP.

$result= mysql_query($query);

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Community
  • 1
  • 1
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

MySQL API is deprecated already. Try using MySQLi API instead. Try this:

connect.php

<?php

$conn=mysqli_connect("localhost","root","****","nameEmail");

if(mysqli_connect_errno()){

echo "Error".mysqli_connect_error();
}

?>

infoQuery.php

<?php
        include('connect.php');

        $query = "SELECT * FROM nameAndEmail";
        $result= mysqli_query($conn,$query);

        while($person = mysqli_fetch_array(result)){

          echo "<h3>" . $person['name'] . "</h3>";
        }

?>
Alex Weinstein
  • 9,823
  • 9
  • 42
  • 59
Logan Wayne
  • 6,001
  • 16
  • 31
  • 49