【发布时间】:2014-06-25 00:38:05
【问题描述】:
我有一个带有复选框的 html 表单,我设法使用数组将值存储到我的数据库中。
我在表单中添加了一个名称字段,并在 mysql 表上添加了一个列。
问题是,新添加的名称字段没有存储任何值,并且导致之前的代码出现故障。我很确定我对 $fname 值的定义不正确,这是完整的 php 代码
$dbcon = mysqli_connect("$host","$username","$password","$db_name") ;
if (!$dbcon) {
die('error connecting to database'); }
echo 'Courses successfully registerd , ' ;
// escape variables for security
$studentid = mysqli_real_escape_string($dbcon, $_GET['studentid']);
$fname = $_POST["name"];
// Get Cources
$name = $_GET['ckb'];
if(isset($_GET['ckb']))
{
foreach ($name as $courcess){
$cc=$cc. $courcess.',';
}
}
//$ckb = join (', ', var_dump($_POST['ckb']));
$sql="INSERT INTO courses (studentid, ckb)
VALUES ('$studentid', '$cc', $fname)";
if (!mysqli_query($dbcon,$sql)) {
die('Error: ' . mysqli_error($dbcon));
}
echo " Thank you for using IME Virtual Registeration ";
mysqli_close($dbcon);
?>
【问题讨论】:
-
您指定提供 2 列,但实际上提供 3?
INSERT INTO courses (studentid, ckb) VALUES ('$studentid', '$cc', $fname) -
如果您在“开启”时报告错误,则表明一组值/列不匹配。
-
谢谢!肯定是这样,但是在上传固定的 connect-mysql.php 文件后我找不到文件...