我工作的php脚本添加数据到mysql表中有4个字段,我想要的所有这些,我想我得到了主要的代码正确因为我从PHP书中复制了代码,然后做了一些更改以反映我正在寻找的特定srcipt,但是当我去测试提交函数时,它只是给我一个白色屏幕而不是成功/错误消息,im有点难以置信从哪里出发。下面是我的代码的副本。PHP表单提交给我一个没有成功消息的白页
<html>
<head>
</head>
<body>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//input validation all required
if (!empty($_POST['airport_name'])) {
$an = trim($_POST['airport_name']);
if (!empty($_POST['airport_code'])){
$ac = trim($_POST['airport_code']);
if (!empty($_POST['airport_lat'])){
$alat = trim($_POST['airport_lat']);
if (!empty($_POST['airport_long'])){
$along = trim($_POST['airport_long']);
//if (!empty($_POST['airport_name'])){
//$an = trip($_POST['airport_name']);
require('/../mysqli_connect.php');
$q = 'INSERT INTO airports (airport_name, airport_code, airport_lat, airport_long) VALUES (?, ?, ?, ?)';
$stmt = mysqli_prepare($dbc, $q);
mysqli_stmt_bind_param($stmt, 'ssss', $an, $ac, $alat, $along);
mysqli_stmt_execute($stmt);
if (mysqli_stmt_affected_rows($stmt) == 1) {
echo '<p>The airport has been added!</p>';
$_POST = array();
} else {
$error = 'The new airport could not be added to the database!';
}
mysqli_stmt_close($stmt);
mysqli_close($dbc);
} //if airport lat
else{
$error = 'Please enter airport lat';
}
} //if airport lat
else{
$error = 'Please enter airport latitude';
}
} //if airport code
else {
$error = 'Please enter an airport code';
}
} //if airport name
else {
$error = 'Please enter an airport name';
}
} // end of submission if
if (isset($error)) {
echo '<h1>Error!</h1>
<p stlye="font-weight: bold; color: #COO">'. $error . 'Please try again</p>';
}
?>
<h1>Add Airport</h1>
<form action="add_apt.php" method="post">
<fieldset><legend>Fill out the for to and and airpot:</legend>
<p><b>Airport Name:</b><input type="text" name="airport_name" size="10" value="<?php if (isset($_POST['airport_name'])) echo $_POST['airport_name']; ?>"/></p>
<p><b>Airport Code:</b><input type="text" name="airport_code" size="4" maxlegnth="4" value="<?php if (isset($_POST['airport_code'])) echo $_POST['airport_code']; ?>"/></p>
<p><b>Airport Lat:</b><input type="text" name="airport_lat" size="10" maxlegnth="40" value="<?php if (isset($_POST['airport_lat'])) echo $_POST['airport_lat']; ?>"/></p>
<p><b>Airport Long:</b><input type="text" name="airport_long" size="10" maxlegnth="40" value="<?php if (isset($_POST['airport_long'])) echo $_POST['airport_Long']; ?>"/></p>
</fieldset>
<div align="center"><input type="submit" name="submit" Value="Add Airport"/></div>
</form>
</body>
</html>
这里是我得到当我emabled错误 警告的错误:mysqli_prepare()预计参数1是mysqli的,在/home5/virtua15/public_html/gatewayaviation/add_apt.php空给出线29
警告:mysqli_stmt_bind_param()预计参数1被mysqli_stmt,空在/home5/virtua15/public_html/gatewayaviation/add_apt.php给定在线路30上
警告:mysqli_stmt_execute()预计参数1被mysqli_stmt,空给定在线31上的/home5/virtua15/public_html/gatewayaviation/add_apt.php
警告:mysqli_stmt_affected_rows()预计参数1被mysqli_stmt,在/home5/virtua15/public_html/gatewayaviation/add_apt.php空给定线路33
警告:mysqli_stmt_close()预计参数1被mysqli_stmt,在给定的/home5/virtua15/public_html/gatewayaviation/add_apt.php第39行上
警告无效:mysqli_close()预计参数1是mysqli的,空在/home5/virtua15/public_html/gatewayaviation/add_apt.php上给出第40行
Mysqli_connect.php脚本
<?php
DEFINE ('DB_USER', '******_******');
DEFINE ('DB_PASSWORD', '*******');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', '******_gateway');
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error());
mysqli_set_charset($dbc, 'utf8');
?>
顶级提示,缩进你的代码......在这种格式下阅读几乎是不可能的。 – 2012-07-19 08:27:06
经常当它给你一个白页这是一个PHP错误,停止正常的页面流:add @ini_set('display_errors','on');在页面顶部看看可能是什么问题。 – kawashita86 2012-07-19 08:27:21
在插入语句中,列计数与值计数不匹配。 – redbirdo 2012-07-19 08:44:58