I have a html form that takes in an account number and a submit value called retrieve. When this retrieve button is clicked I need certain attributes to print out based on the customer's account number. I tried this in my code. For some reason it enters the function but does not print any of the values of the row out. I am very confused and not sure where to go from here to solving the issue. I do have dummy data in mysqlworkbench. I have used the same db connection for other pages and it worked fine when I posted a form back into the database. So I am not sure what the issue is exactly.
I am not sure if the database lost connection where I call the query in result? It prints out the query of result, but when I try to do a var_dump after the query it is saying NULL. So something might be wrong there?
I added the error check when I create the variable $result within the function and every time I add the account number it print's out Could Not Enter Data but not the mysql error.
My Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Create Account</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="header">Our Really Cool Banking App</div>
<div id="leftcolumn">
<!-- Creating Buttons here -->
<div id="nav">
<ul>
<li><a href="banking.php">Home</a></li>
<li><a href="checking.php">Checking</a></li>
<li><a href="savings.php">Savings</a></li>
<li><a href="createaccount.php">Create Account</a></li>
<li><a href="createloan.php">Create Loan</a></li>
</ul>
</div>
</div>
<h2>Checking Account Information Details</h2>
<div class="inputBox">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Account Number: <input type="text" name="accountNum"><br>
<input type="submit" id="Retrieve" name="Retrieve" value="Retrieve">
</form>
</div>
<?php
//error_reporting(E_ALL);
//ini_set('display_errors', 1);
$properties = parse_ini_file("properties.ini");
if ( !( $database = mysql_connect( $properties["dbUrl"], $properties["username"], $properties["password"] ) ) )
{
echo "<p> Be sure to fill out information in the properties.ini file </p>";
die( "Could not connect to database </body></html>" );
}
echo $_POST['Retrieve'] . "is the value";
if ( !mysql_select_db( $properties["dbName"], $database ) )
die( "Could not open the database </body></html>" );
if (isset($_POST['Retrieve']))
{
accountInfo();
}
function accountInfo() {
$currentAccountNum = $_POST[accountNum];
$data = "SELECT * FROM Account WHERE AcctNum = '$currentAccountNum'";
$result=mysqli_query($database, $data);
if(! $result )
{
die('Could not enter data: ' . mysql_error());
}
while($row = mysqli_fetch_array($result)) {
echo $row['AcctNum'];
echo "<br>";
echo $row['MemberId'];
echo "<br>";
echo $row['creationDate'];
echo "<br>";
echo $row['CreatedByEmployee'];
echo "<br>";
echo $row['type'];
echo "<br>";
}
}
mysql_close( $database );
?>
</body>
</html>