我正在尝试通过表单插入数据,但它不起作用。请帮忙:
表单页码:
<form class="form-horizontal" action="add_asc_submit.php" enctype="text/plain" method="post">
<div class="control-group">
<label for="asc_center_name" class="control-label">ASC Center Name</label>
<div class="controls with-tooltip">
<input type="text" name="asc_center_name" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_user_id" class="control-label">ASC User ID</label>
<div class="controls with-tooltip">
<input type="text" name="asc_user_id" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_user_password" class="control-label">ASC User Password</label>
<div class="controls with-tooltip">
<input type="password" name="asc_user_password" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_director_name" class="control-label">ASC Director Name</label>
<div class="controls with-tooltip">
<input type="text" name="asc_director_name" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_center_address" class="control-label">ASC Center Address</label>
<div class="controls with-tooltip">
<input type="text" name="asc_center_address" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_contact_number" class="control-label">ASC Contact Number</label>
<div class="controls with-tooltip">
<input type="text" name="asc_contact_number" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_center_city" class="control-label">ASC Center City</label>
<div class="controls with-tooltip">
<input type="text" name="asc_center_city" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<label for="asc_center_email" class="control-label">ASC Email Id</label>
<div class="controls with-tooltip">
<input type="text" name="asc_center_email" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
<br/>
<div class="control-group">
<div class="controls with-tooltip">
<input type="submit" name="submit" class="span6 input-tooltip" data-placement="bottom" required/>
</div>
</form>
add_asc_submit.php页面详情:
<?php
include('config.php');
if(isset($_POST['submit']))
{
if(! get_magic_quotes_gpc())
{
$asc_center_name=addslashes ($_POST['asc_center_name']);
$asc_user_id=addslashes($_POST['asc_user_id']);
$asc_user_password=addslashes($_POST['asc_user_password']);
$asc_director_name=addslashes($_POST['asc_director_name']);
$asc_center_address=addslashes($_POST['asc_center_address']);
$asc_contact_number=addslashes($_POST['asc_contact_number']);
$asc_center_city=addslashes($_POST['asc_center_city']);
$asc_center_email=addslashes($_POST['asc_center_email']);
}
else
{
$asc_center_name=$_POST['asc_center_name'];
$asc_user_id=$_POST['asc_user_id'];
$asc_user_password=$_POST['asc_user_password'];
$asc_director_name=$_POST['asc_director_name'];
$asc_center_address=$_POST['asc_center_address'];
$asc_contact_number=$_POST['asc_contact_number'];
$asc_center_city=$_POST['asc_center_city'];
$asc_center_email=$_POST['asc_center_email'];
/*}*/
$sql = mysqli_query($conn,"INSERT INTO add_asc(asc_center_name, asc_user_id, asc_user_password, asc_director_name, asc_center_address, asc_center_number, asc_center_city, asc_center_email) VALUES('$asc_center_name', '$asc_user_id', '$asc_user_password', '$asc_director_name', '$asc_center_address','$asc_center_number','$asc_center_city','$asc_center_email')");
if (mysqli_query($sql))
{
echo "ASC Added Succesfully.";
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>
的config.php
<?php
$conn=mysqli_connect("localhost","root","", "rgcsm");
error_reporting(-1);
ini_set('display_errors', 'On');
?>
当我运行以下代码时,Page将我重定向到add_asc_submit.php页面,但没有显示任何错误,也没有将数据插入数据库。请帮助...我也使用谷歌搜索但没有取得任何成功。
非常感谢提前。
答案 0 :(得分:1)
您运行查询并将结果存储在$ sql中,然后再次对结果运行查询?
尝试:
<?php
include('config.php');
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!get_magic_quotes_gpc()) {
$asc_center_name=addslashes ($_POST['asc_center_name']);
$asc_user_id=addslashes($_POST['asc_user_id']);
$asc_user_password=addslashes($_POST['asc_user_password']);
$asc_director_name=addslashes($_POST['asc_director_name']);
$asc_center_address=addslashes($_POST['asc_center_address']);
$asc_contact_number=addslashes($_POST['asc_contact_number']);
$asc_center_city=addslashes($_POST['asc_center_city']);
$asc_center_email=addslashes($_POST['asc_center_email']);
} else {
$asc_center_name=$_POST['asc_center_name'];
$asc_user_id=$_POST['asc_user_id'];
$asc_user_password=$_POST['asc_user_password'];
$asc_director_name=$_POST['asc_director_name'];
$asc_center_address=$_POST['asc_center_address'];
$asc_contact_number=$_POST['asc_contact_number'];
$asc_center_city=$_POST['asc_center_city'];
$asc_center_email=$_POST['asc_center_email'];
}
$sql = mysqli_query($conn, "INSERT INTO add_asc(asc_center_name, asc_user_id, asc_user_password, asc_director_name, asc_center_address, asc_center_number, asc_center_city, asc_center_email) VALUES('$asc_center_name', '$asc_user_id', '$asc_user_password', '$asc_director_name', '$asc_center_address','$asc_center_number','$asc_center_city','$asc_center_email')");
if ($sql) {
echo "ASC Added Succesfully.";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
?>