我有一个表格来统计我大学的类(class)注册,其中一个字段是“studentid”,将表格连接到数据库似乎是成功的,并且自动递增的主要字段工作正常,但是输入学生 ID 和提交表格每次都失败,并且添加了一 strip 有“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);
?>
最佳答案
method="POST"
以形式重复
这样检查学生id:
$studentid = mysqli_real_escape_string($dbcon, $_POST['studentid']); echo $studentid;
设置后可以打印$sql变量到
关于php - MySQL 数据库保存 0 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23301789/