gpt4 book ai didi

php - 错误: Unknown column '' in 'field list' MySQL error

转载 作者:行者123 更新时间:2023-11-29 08:19:43 25 4
gpt4 key购买 nike

我无法插入数据。错误是:

Error: Unknown column '' in 'field list'

它是一个简单的 HTML 表单页面,用户将数据插入到数据库 dB 中。确实需要帮助。我无法得到错误的东西。我是新手。

<?php
$con=mysqli_connect("localhost", "root", "root","dB");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$enrollno=$_POST['enrollno'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$fathername=$_POST['fathername'];
$coursename=$_POST['coursename'];
$yearsem=$_POST['yearsem'];
$facultyno=$_POST['facultyno'];
$hostel=$_POST['hostel'];
$roomno=$_POST['roomno'];
$email=$_POST['email'];
$mobileno=$_POST['mobileno'];
$peradd=$_POST['peradd'];
$district=$_POST['district'];
$state=$_POST['state'];
$amount=$_POST['amount'];
$pwd=$_POST['pwd'];
$tnc=$_POST['tnc'];

$sql="INSERT INTO registration (enrollno, fname, lname, fathername, coursename, yearsem, facultyno, hostel, roomno, email, mobileno, peradd, district, state, amount, pwd, tnc) VALUES ('$enrollno',`$fname`,`$lname`,`$fathername`,`$coursename`,`$yearsem`,`$facultyno`,`$hostel`,`$roomno`,`$email`,`$mobileno`,`$peradd`,`$district`,`$state`,`$amount`,`$pwd`,'$tnc')";

if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";

mysqli_close($con);
?>

最佳答案

您正在使用反引号[用于列]作为变量。使用单引号。尝试下面的代码

$sql="INSERT INTO registration (enrollno, fname, lname, fathername, coursename, yearsem, facultyno, hostel, roomno, email, mobileno, peradd, district, state, amount, pwd, tnc) VALUES ('$enrollno','$fname','$lname','$fathername','$coursename','$yearsem','$facultyno','$hostel','$roomno','$email','$mobileno','$peradd','$district','$state','$amount','$pwd','$tnc')";

关于php - 错误: Unknown column '' in 'field list' MySQL error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19755944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com