[英]Storing Data to MySQL database from html form with checkboxes
I have an html form with checkboxes and I managed to store the values using an array to my database . 我有一个带复选框的html表单,并且设法使用数组将值存储到数据库中。
I added a name field to the form, and added a column on mysql table . 我在表单中添加了名称字段,并在mysql table上添加了一列。
The problem is, the newly added name field is not storing any values and is malfunctioning the previous code. 问题是,新添加的名称字段未存储任何值,并且使先前的代码出现故障。 I'm pretty sure my definition for the
$fname
value is incorrect, here is the full php code 我很确定
$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);
?>
$sql="INSERT INTO courses (studentid, ckb)
VALUES ('$studentid', '$cc', $fname)";
is your problem. 是你的问题。 You are attempting to insert three values into two fields.
您试图将三个值插入两个字段。 You need to add your new field after ckb so that the argument $fname can be inserted into it.
您需要在ckb之后添加新字段,以便可以将参数$ fname插入到其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.