-2

I have two files index.php and header.php

This is header.php

<?php
$host ="localhost";
$user ="hosting_user";
$db = "hosting_dbname";
$pass ="lamepassword";

$odb = new PDO("mysql:host=" . $host . ";dbname= . $db, $user, $pass);
?>

this is index.php

<?php require_once("header.php");?>
<html>
<head>
<title>Web Dev 1</title>
</head>

<body>
<form method="post" action">
    Name: <input type="text" id="Box_num" name="Box_num" /><br />
    Age: <input type="text" id="Names" name="Names" /><br />
    <input type="submit" value="add" />
    </form>
    <?php
        $query = "SELECT * FROM Owners";
        $result =$odb->query($query);
        if($result->)rowCount() > 0) {
            foreach($result as $item){
                echo($item['Box_num'] .<br />/n");
        }
    }
    </body>
</html>

When I load index.php, all I get is a blank screen. When I use mysqli it works but doesnt load the sql query

liquidacid
  • 108
  • 1
  • 9

1 Answers1

1

There appears to be a few PHP syntax errors here.

It should read:

$odb = new PDO("mysql:host=" . $host . ";dbname=" . $db, $user, $pass);

There also seems to be errors in your syntax in index.php. My suggestion would be to enable error reporting so you can detect these errors yourself. You can also try using PHP's lint tool via the command line php executable. That will also detect fatal parser errors.

Ex:

php -l /path/to/index.php
Community
  • 1
  • 1
DJ Sipe
  • 1,286
  • 13
  • 12