您好我的问题是我创建了一个表单并将所有html POST数据存储到php变量中,并希望运行查询以将该数据插入到我的本地数据库中。我知道我的数据库是连接的。当我填写表单时,它打印出错误,因为查询不起作用,但实际上并没有打印出确切的查询。我无法弄清楚出了什么问题或如何从表单中更新我的数据库。任何帮助都会非常感谢!
代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!--<?php
require_once('dbConnection.php');
?>-->
<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>
<div class="inputBox">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Member ID: <input type="text" name="memberId"><br>
Balance: <input type="text" name="Balance"><br>
PIN: <input type="text" name="pin"><br>
Created Date: <input type="text" name="createdDate"><br>
Initial Balance: <input type="text" name="initBalance"><br>
Employee ID: <input type="text" name="employeeId"><br>
Type: <input type="radio" name="accounttype" value="Checking">Checking
<input type="radio" name="accounttype" value="Savings">Savings<br>
<input type="submit" value="Submit">
</form>
</div>
<?php
$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>" );
}
// open our database
if ( !mysql_select_db( $properties["dbName"], $database ) )
die( "Could not open the database </body></html>" );
$memId = mysqli_real_escape_string($database, $_POST["memberId"]);
$balance = mysqli_real_escape_string($database, $_POST["Balance"]);
$pin = mysqli_real_escape_string($database, $_POST["pin"]);
$createdDate = mysqli_real_escape_string($database, $_POST["createdDate"]);
$initBalance = mysqli_real_escape_string($database, $_POST["initBalance"]);
$employeeId = mysqli_real_escape_string($database, $_POST["employeeId"]);
$type = mysqli_real_escape_string($database, $_POST["accounttype"]);
$sql="INSERT INTO Account (MemberId, Balance, PIN, creationDate, InitialBalance, CreatedByEmployee, type)
VALUES ('$memId', '$balance', '$pin', '$createdDate', '$initBalance', '$employeeId', '$type')";
if (!mysqli_query($database,$sql)) {
die('Error: ' . mysqli_error($database));
}
echo "1 record added";
mysql_close( $database );
?>
</body>
</html>