尽管PHP,MYSQL中没有错误,但INSERT INTO不会插入任何数据

时间:2019-01-14 04:50:09

标签: php mysql

我正在尝试创建将数据添加到SQL数据库的表单。它首先为我获取另一个表中已经存在的数据,然后将它们与创建的表单一起添加到数据库中。但是,即使没有错误,也不会插入数据,但返回的行数为0。我试图修复了几个小时,但我想不出什么能解决它。

这是我的代码,用于从现有表中获取数据:

    <form action="" method = "POST" class="form-horizontal">
                                <fieldset>
                                    <legend>Action Taker:</legend>
<label class="control-label col-lg-4">Employee Name: </label>
<input type="text" name="employ_first" value ="<?php echo (isset($row['first_name'])&&!empty($row['first_name'])) ? $row['first_name'] : ''; ?>" disabled>
<input type="text" name="employ_second" value ="<?php echo (isset($row['second_name'])&&!empty($row['second_name'])) ? $row['second_name'] : ''; ?>" disabled>
<label class="control-label col-lg-4">Staff Comment: </label>
<input type="text" name="reason_emp" value ="<?php echo (isset($row['reason'])&&!empty($row['reason'])) ? $row['reason'] : ''; ?>" size="100" disabled>
 <div>
                                                    &nbsp;  &nbsp;  &nbsp;
                                            </div>
                                        <div>
                                            <label class="control-label col-lg-4">Add Respond Comment:</label>
                                            <div class="col-lg-4">
                                                <input type="text" name="admin_respond" class="form-control" size="50px"/>
                                            </div>
                                            <div>
                                                    &nbsp;  &nbsp;  &nbsp;
                                            </div>
                                        </div>
    <input type="submit" name="submit" class="form-control"  value="Add" />
    </form>

这是FORM代码:

<form action="meeting_schema.php" method = "POST" class="form-horizontal">
<h3>Fill The Form For Investigation:</h3>
<div> 
<label>Type of Investigation:</label>
<input name="type" type="text">
<label>Set Date:</label>
<input name="set_on_date" type="date">
<label>Set Time:</label>
<input name="set_on_time" type="time">
<label>Assigned to:</label>
<input name="assigned_to" type="text">
<input type="submit" name="add_meeting" value="Create Meeting" />
</div>
</form>

这是我的动作php文件Meeting_schema:

<?php
 $hostnames = "localhost";
    $usernames = "u3253997...";
    $passwords = "Ws.....";
    $databaseNames = "u3253997...";
    $conns= mysqli_connect($hostnames, $usernames, $passwords, $databaseNames);
 if (!$conns) {

die('Connection failed: ' . mysqli_connect_error());

        }
if (!$conns) {

die("Connection failed: " . mysqli_connect_error());
}
if(isset($_POST['add_meeting'])){

$stmt = $conns->prepare("INSERT INTO `emp_inv` (`meeting.id`,`employ_first`,`employ_second`,`reason`,`type`,`set_on_date`, `set_on_time`, `set_by`, `assigned_to`) VALUES (NULL,?,?,?,?,?,?,?,?)");


if (!$stmt) {
        echo "There is an error in the source code, please contact support to fix the problem.";
    }
    else {

$stmt->bind_param('ssssssss', $_POST['employ_first'], $_POST['employ_second'], $_POST['reason_emp'], $_POST['type'], $_POST['set_on_date'], $_POST['set_on_time'], $_SESSION['set_by'], $_POST['assigned_to']);
$stmt->execute();

echo "Meeting has been created";
header("location:meetings.php");
} 
}   

?>

1 个答案:

答案 0 :(得分:-1)

使用以下代码...

$stmt->bind_param('ssssssss',$employ_first,$employ_second, $reason_emp,$type,$set_on_date,$set_on_time,$set_by,$assigned_to);

$employ_first = $_POST['employ_first'];
$employ_second = $_POST['employ_second']; 
$reason_emp = $_POST['reason_emp'];
$type = $_POST['type']; 
$set_on_date = $_POST['set_on_date']; 
$set_on_time = $_POST['set_on_time']; 
$set_by = $_SESSION['set_by']; 
$assigned_to = $_POST['assigned_to'];
$stmt->execute();
echo "Meeting has been created";

$stmt->close();