这是我的第一篇文章。请温柔。
我正在为设备服务历史创建一个基本数据库。我最初使用MySQL。但是,在阅读了很多帖子后,我试图改成mysqli。我页面中的前两个数据库连接正常工作。但第三个是在我的服务历史部分发布“0000-00-00 $ tech $ history”。当我使用MySQL vs mysqli时,一切正常。我确定我错过了一些简单的事情。我搜索过谷歌,找不到任何解决此问题的方法。
这是给我提问的页面的php部分。提前谢谢。
//This section sends service data to the specified database//
$con = mysqli_connect("localhost","root","pass","bed_logs");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if(isset($_POST['add']))
if(! get_magic_quotes_gpc() )
{
$history = addslashes ($_POST['history']);
$service_date = addslashes ($_POST['service_date']);
$tech = addslashes ($_POST['tech']);
}
else
{
$tag5156 = $_POST['history']['tech']['service_date'];
}
$sql = 'INSERT INTO tag5156 (service_date,tech,history) VALUES ("$service_date","$tech","$history")';
while ($row = mysqli_fetch_assoc($retval))
{
print_r ($row);
}
$retval = mysqli_query($con,$sql);
if(! $retval )
{
die('Could not enter data: ' . mysqli_error($con));
}
{
echo "<CENTER>Record Updated</CENTER><BR><BR>";
}
mysqli_close($con);
HTML似乎运行良好。
<!--This is the submit form-->
<form action="<?php $_PHP_SELF ?>" method="post">
<div>
<td style="width: 200px; height: 28px;">
<table style="width: 100%">
<tr>
<!--SERVICE DATE-->
<td style="height: 45px" class="auto-style2"><strong>Service Date:</strong></td>
<td style="height: 45px; width: 132px;">
<input id="service_date" name="service_date" value="<?php echo date('Y- m-d'); ?>"</td style="width: 80px">
<!--TECHNICIAN NAME-->
<td style="height: 45px" class="auto-style2">
<strong>Tech:</strong></td>
<td style="height: 45px; width: 165px;">
<input id="tech" name="tech" type="text"></td>
<!--WORK PERFORMED-->
<td style="height: 45px" class="auto-style2"><strong>Work
Performed:</strong></td>
<td style="height: 45px">
<input id="history" name="history" style="width: 750px; height: 25px"
type="text"></td>
</tr>
</table>
<!--BUTTON TO UPDATE SERVICE RECORD-->
<input id="add" name="add" type="submit" value="Update Service Record"
onClick="return empty()">
答案 0 :(得分:0)
这一行:
$sql = 'INSERT INTO tag5156 (service_date,tech,history) VALUES ("$service_date","$tech","$history")';
应该是
$sql = "INSERT INTO tag5156 (service_date,tech,history) VALUES ('$service_date','$tech','$history')";
或
$sql = 'INSERT INTO tag5156 (service_date,tech,history) VALUES ("'.$service_date.'","'.$tech.'","'.$history.'")';
有关原因的详细信息,请参阅this answer其他问题......