我有一個表格可以在我的大學進行課程註冊統計,其中一個字段是將表單連接到數據庫的「studentid」似乎是成功的,並且帶有自動增量的主要字段正在工作就好了,但是進入學生證和提交表單失敗,每一次一個新的記錄添加一個「0」值...MySQL數據庫保存0值
這是HTML代碼
<div class="content">
<form action="connect-mysql.php" method="POST" enctype="text/plain" id="form3" name="form3" method="post">
<table width="100%" border="0">
<tr>
<td width="50%" bgcolor="#e3e3e3"><center>
Student ID :
</center></td>
<td width="50%" bgcolor="#e3e3e3">
<span id="sprytextfield1">
<label for="studentid"></label>
<input name="studentid" type="text" id="studentid" onblur="MM_validateForm('studentid','','NisNum');return document.MM_returnValue" maxlength="11" />
*<span class="textfieldRequiredMsg">A value is required.</span></span>
</td>
PHP代碼
<?php
$host="fdb7.biz.nf" ;`enter code here`
$username="1662822_db1" ;
$password="421343" ;
$db_name="1662822_db1" ;
$tbl_name="courses" ;
$dbcon = mysqli_connect("$host","$username","$password","$db_name") ;
if (!$dbcon) {
die('error connecting to database'); }
echo 'you have connected sucessfully' ;
// escape variables for security
$studentid = mysqli_real_escape_string($dbcon, $_POST['studentid']);
$sql="INSERT INTO courses (studentid)
VALUES ('$studentid')";
if (!mysqli_query($dbcon,$sql)) {
die('Error: ' . mysqli_error($dbcon));
}
echo "1 record added";
mysqli_close($dbcon);
?>
在窗體中取出'enctype =「text/plain」'。 –
你有沒有試過驗證$ _POST ['studentid']能幫助你? –
當你說'每次失敗'時,你的意思是什麼 – JohnnyFaldo