-1

I am trying to build a table using in PHP with some text coming from mysql database:

However, when I echo the table, the page comes up as blank

Here's my code

<!DOCTYPE html>
<html lang="en">

    <title>Pre Order</title>

</head>
<body>
<div class="page">

<?php 
include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 
$conn2 = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); 


$form=$_POST;
$a=$form['a'];
$b=$form['b'];
$c=$form['c'];
$accountnumber=$form['accountnumber']

$stmt = $conn->query("SELECT * FROM Contracts WHERE A='$a' AND B='$b' AND C='$c'");
$stmt2 = $conn2->query("SELECT * FROM Customers WHERE CustomerCode='$accountnumber'");

$data = '';

    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { 
    while ($row2 = $stmt2->fetch(PDO::FETCH_ASSOC)) {


$data .= "<table>";
$data .= "<tr><td>Account Number: </td>";


echo $data;
}
}

?>
</div>
</body>
</html>

However, when I remove the mysql connection, the echo works fine.

The file is a .php file.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
miababy
  • 225
  • 2
  • 16

1 Answers1

1

Without seeing more code, there's nothing more I can suggest, however:

include_once "connect.php";
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

$contracts = $conn->prepare('SELECT * FROM Contracts WHERE A = :a AND B = :b AND C = :c');
$contracts->bindParam(':a', $_POST['a']);
$contracts->bindParam(':b', $_POST['b']);
$contracts->bindParam(':c', $_POST['c']);
$contracts->execute();

$customers = $conn->prepare('SELECT * FROM Customers WHERE CustomerCode = :code');
$customers->bindParam(':code', $_POST['accountnumber']);
$customers->execute();

while ($customer = $customers->fetch(PDO::FETCH_ASSOC))
    print_r($customer);

while ($contract = $contracts->fetch(PDO::FETCH_ASSOC))
   print_r($contract);

One connection, and make sure you're preparing and executing your queries. I think because you didn't do this, a single quote or an invalid character broke your query.

Dave Chen
  • 10,887
  • 8
  • 39
  • 67
  • `Fatal error: Call to a member function bindParam() on a non-object in` getting this error for `$contracts->bindParam(':a', $_POST['a']);` – miababy Feb 19 '16 at 07:01
  • Make sure your table Contracts has the columns A, B, and C, and that your Customers table has the column CustomerCode. Make sure `$conn` is connected properly, and also `print_r($conn->->errorInfo());` right after the prepare. – Dave Chen Feb 19 '16 at 08:22