我发现在互联网上插入数据库代码,用它来尝试和它的工作。但是,在我添加了更多列后,我在将数据插入数据库时出错。我正在使用此代码
error_reporting(E_ALL);
ini_set('display_errors','on');
确定错误位置,但它在编码时没有显示错误。只会出错。任何人都可以帮助我找出我的错误和我的代码错误吗?
这是我的insert2_db.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body,td,th {
font-family: Tahoma, Geneva, sans-serif;
}
</style>
</head>
<body>
<script type="text/javascript">function checkinput() {
var id_mesin = document.getElementById('id_mesin').value;
if(!id_mesin.match(/\S/)) {
alert ('Please enter Machine ID');
return false;
} else {
return true;
}
}
</script>
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form_insert" method="post" action="insert_ac.php" onSubmit="return checkinput(this)">
<table width="100%" height="398" border="0" cellpadding="3" cellspacing="1">
<tr>
<td colspan="9"><strong>Insert Data Into EXA_mySQL Database </strong></td>
</tr>
<tr>
<td width="106">MACHINE ID</td>
<td width="6">:</td>
<td colspan="3"><input name="id_mesin" type="text" id="id_mesin"></td>
<td colspan="2">BRAND</td>
<td width="9">:</td>
<td width="164"><select name="jenama">
<option selected>Please select :</option>
<option value="SHARP">SHARP</option>
<option value="TOSHIBA">TOSHIBA</option>
<option value="CANON">CANON</option>
<option value="SAMSUNG">SAMSUNG</option>
<option value="MEXTEC">MEXTEC</option>
</select></td>
</tr>
<tr>
<td>MODEL</td>
<td>:</td>
<td colspan="3"><input name="model" type="text" id="model"></td>
<td colspan="2">METER START</td>
<td>:</td>
<td><input name="meter_awal" type="text" id="meter_awal" value="0"></td>
</tr>
<tr>
<td>SERIAL NO</td>
<td>:</td>
<td colspan="3">MACHINE</td>
<td colspan="2">FEEDER</td>
<td> </td>
<td>FINISHER</td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"><input name="siri_mesin" type="text" id="siri_mesin"></td>
<td colspan="3"><input name="siri_feeder" type="text" id="siri_feeder"></td>
<td><input name="siri_finisher" type="text" id="siri_finisher"></td>
</tr>
<tr>
<td>STOCK IN</td>
<td>:</td>
<td width="58">DATE</td>
<td width="8">:</td>
<td width="220"><input type="text" name="stok_in" id="stok_in"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="in_do" id="in_do"></td>
</tr>
<tr>
<td>LOCATION</td>
<td>:</td>
<td colspan="3"><select name="lokasi">
<option selected>Please select :</option>
<option value="HQ WAREHOUSE">HQ WAREHOUSE</option>
<option value="CHENDERING WAREHOUSE">CHENDERING WAREHOUSE</option>
</select></td>
<td colspan="2">J.S.O</td>
<td>:</td>
<td><input type="text" name="js_order" id="js_order"></td>
</tr>
<tr>
<td>STOCK OUT</td>
<td>:</td>
<td>DATE</td>
<td>:</td>
<td><input type="text" name="stok_out" id="stok_out"></td>
<td colspan="2">D.O NO </td>
<td>:</td>
<td><input type="text" name="out_do" id="out_do"></td>
</tr>
<tr>
<td>CUSTOMER</td>
<td>:</td>
<td colspan="7"><input name="pelangan" type="text" id="pelangan" size="90"></td>
</tr>
<tr>
<td>ADDRESS</td>
<td>:</td>
<td colspan="7"><textarea name="pelangan_alamat" cols="69" id="pelangan_alamat"></textarea></td>
</tr>
<tr>
<td>CONTACT PERSON</td>
<td>:</td>
<td colspan="4"><input name="pelangan_person" type="text" id="pelangan_person" size="50"></td>
<td width="109">NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="pelangan_no" id="pelangan_no"></td>
</tr>
<tr>
<td>TECHNICIAN INCHARGE</td>
<td>:</td>
<td colspan="4"><input name="tech" type="text" id="tech" size="50"></td>
<td>NO TEL/HP</td>
<td>:</td>
<td><input type="text" name="tech_no" id="tech_no"></td>
</tr>
<tr>
<td>STATUS</td>
<td>:</td>
<td colspan="3"><select name="status">
<option selected>Please select :</option>
<option value="ORDER PURCHASE">ORDER PURCHASE</option>
<option value="RENTAL">RENTAL</option>
<option value="HIRE PURCHASE">HIRE PURCHASE</option>
</select></td>
<td colspan="3"> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="3"> </td>
<td colspan="3"><input type="reset" value="Clean" /></td>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>
和我的insert_ac.php
<?php
//Start session
session_start();
//Check whether the session variable SESS_MEMBER_ID is present or not
if(!isset($_SESSION['username']) || (trim($_SESSION['password']) == '')) {
header("location: login.php");
exit();
}
?>
<html>
<head>
<title>EXA_mySQL</title>
<script type="text/javascript">
<!--
function CloseWindow() {
window.close();
window.opener.location.reload();
}
//-->
</script>
</head>
<body>
<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
$con=mysqli_connect("localhost","root","admin","exa");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id_mesin=$_POST['id_mesin'];
$jenama=$_POST['jenama'];
$model=$_POST['model'];
$siri_mesin=$_POST['siri_mesin'];
$siri_feeder=$_POST['siri_feeder'];
$siri_finisher=$_POST['siri_finisher'];
$meter_awal=$_POST['meter_awal'];
$lokasi=$_POST['lokasi'];
$status=$_POST['status'];
$pelangan=$_POST['pelangan'];
//$rekod=$_POST['rekod'];
$stok_in=$_POST['stok_in'];
$stok_out=$_POST['stok_out'];
$in_do=$_POST['in_do'];
$out_do=$_POST['out_do'];
$pelangan_alamat=$_POST['pelangan_alamat'];
$pelangan_no=$_POST['pelangan_no'];
$pelangan_person=$_POST['pelangan_person'];
$js_order=$_POST['js_order'];
$tech=$_POST['tech'];
$tech_no=$_POST['tech_no'];
//$sql2="SELECT * FROM aset where id_mesin = '".$id_mesin."'";
//$result2=mysqli_query($con, $sql2);
$sql="INSERT INTO aset(id_mesin, jenama, model, siri_mesin, siri_feeder, siri_finisher, meter_awal, lokasi, status, pelangan, stok_in, stok_out, in_do, out_do, pelangan_alamat, pelangan_no, pelangan_person, js_order, tech, tech_no) VALUES('$id_mesin', '$jenama', '$model', '$siri_mesin', $siri_feeder, $siri_finisher, '$meter_awal', '$lokasi', '$status', '$pelangan', '$stok_in', '$stok_out', '$in_do', $out_do, $pelangan_alamat, '$pelangan_no', '$pelangan_person', '$js_order', '$tech', '$tech_no')";
$result=mysqli_query($con, $sql);
if($result){//if ($result2 !== 1){
echo "Successful";
echo "<BR>";
echo "<th><form>";
echo "<input type='button' onClick='CloseWindow()' value='Back to Exa_mySQL'>";
echo "</form></th>}";
}//}
else {
echo "Data error, please check your submit.";
echo "<BR>";
echo "<a href='insert.php'>Back to insert form</a>";
}
mysqli_close($con);
?>
</body>
</html>
我也在我的表单上使用一些下拉列表作为输入,初始值=请选择:并且它具有空值。我无法插入数据,即使我将所有信息都放在我的插入表单上,所有这些都归结为此错误结果。
echo "Data error, please check your submit.";