这可能是迄今为止试图获得一些帮助的这篇文章的第四次编辑。我已经多次重写了这段代码,但似乎没有什么工作正常。我已经在这个项目上工作了大约5个月,仍然找不到合适的答案。
目前,除了从表单插入数据外,我已经能够使用语法。插入的内容是空值而不是输入字段中的字符串。
最近的迭代是:
$con = mysqli_connect(host, username, password, db_name1);
if($con->connect_errno){
printf("Connect failed: %s\n", $connection->error);
exit();
}
$query = "Insert into hdd_tracking (`ticket`,`serial`,`vol_name`,`drivetype`,`project`,`notes`,`encrypt_date`,`encryption_password`,`fedX_tracking`,`fedX_rt_tracking`)
VALUES (?,?,?,?,?,?,?,?,?,?)";
$stmt = $con->stmt_init();
if($stmt-> prepare($query)){
$stmt->bind_param('isssssssss',
$_POST['ticket'],
$_POST['serial'],
$_POST['vol_name'],
$_POST['drivetype'],
$_POST['project'],
$_POST['notes'],
$_POST['encrypt_date'],
$_POST['encryption_password'],
$_POST['fedX_tracking'],
$_POST['fedX_rt_tracking']);
}
$ticket = ISSET( $_POST['ticket']);
$serial = ISSET( $_POST['serial']);
$vol_name = ISSET( $_POST['vol_name']);
$drivetype = ISSET( $_POST['drivetype']);
$project = ISSET( $_POST['project']);
$notes = ISSET( $_POST['notes']);
$encrypt_date = ISSET( $_POST['encrypt_date']);
$encryption_password = ISSET( $_POST['encryption_password']);
$fedX_tracking = ISSET( $_POST['fedX_tracking']);
$fedX_rt_tracking = ISSET( $_POST['fedX_rt_tracking']);
$run = $stmt ->execute();
var_dump($stmt);
if($run){
$stmt -> close();
mysqli_close($con);
}else{
echo "Failure";
}
表格如下:
<form class="form-inline insertDrive" role="form" name="insert" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table class="insertHDD" style="border-collapse: separate; border-spacing: 10px;">
<tr align="left">
<td>
<label class="center">Ticket:</label>
</td>
<td>
<input type="email" class="form-control" name="ticket" placeholder="Ticket">
</td>
</tr>
<tr>
<td>
<label class="center">Volume Name:</label>
</td>
<td>
<input type="text" class="form-control" name="vol_name" placeholder="Volume Name">
</td>
<td>
<label class="center">Type:</label>
</td>
<td>
<input type="email" class="form-control" name="drivetype" placeholder="Type">
</td>
</tr>
<tr>
<td>
<label class="center">Project:</label>
</td>
<td>
<input type="text" class="form-control" name="project" placeholder="Project">
</td>
<td>
<label class="center">Encryption:</label>
</td>
<td>
<input type="email" class="form-control" name="encryption_password" placeholder="Encryption">
</td>
</tr>
<tr>
<td>
<label class="center">Date:</label>
</td>
<td>
<input type="text" class="form-control" name="encrypt_date" placeholder="Date">
</td>
<td>
<label>Serial:</label>
</td>
<td>
<input type="email" class="form-control" name="serial" placeholder="Serial">
</td>
</tr>
<tr>
<td>
<label class="center">Tracking:</label>
</td>
<td>
<input type="text" class="form-control" name="fedX_tracking" placeholder="Tracking">
</td>
<td>
<label class="center">Return:</label>
</td>
<td>
<input type="text" class="form-control" name="fedX_rt_tracking" placeholder="Return">
</td>
</tr>
<tr>
<td>
<label class="center">Notes:</label>
</td>
<td colspan="3">
<input type="text" width="200px" class="form-control" name="notes" placeholder="Notes">
</td>
</tr>
<tr>
<td colspan="4">
<a class="btn btn-small btn-info" name="submit" name="submit">Submit</a>
</td>
</tr>
</table>
</form>
我已经使用id
到name
进行了更正,我仍然得到空值。 var_dump($stmt)
返回:
object(mysqli_stmt)#1(10){[&#34; affected_rows&#34;] =&gt; int(1)[&#34; insert_id&#34;] =&gt; int(1262)[&#34; num_rows&#34;] =&gt; int(0)[&#34; param_count&#34;] =&gt; int(10)[&#34; field_count&#34;] =&gt; int(0)[&#34; errno&#34;] =&gt; int(0)[&#34;错误&#34;] =&gt; string(0)&#34;&#34; [&#34; error_list&#34;] =&GT; array(0){} [&#34; sqlstate&#34;] =&gt; string(5)&#34; 00000&#34; [&#34; ID&#34;] =&GT; int(1)}
仍然没有得到这个。
答案 0 :(得分:0)
是问题是您正在使用id
,您应该在html表单name
中使用input
。
例如
<input type="email" class="form-control" id="ticket" placeholder="Ticket">
应该是
<input type="email" class="form-control" name="ticket" placeholder="Ticket">
使用php $_POST['']
时,您正在按名称