Error: Unknown column '' in 'field list' MySQL error

后端 未结 2 1061
有刺的猬
有刺的猬 2021-01-17 06:04

I am unable to insert data. The error is:

Error: Unknown column \'\' in \'field list\'

It is simpy an HTML form page and data

相关标签:
2条回答
  • 2021-01-17 06:51

    You are using backticks[used for columns] for variables. Make use of single quotes. Try the below code

    $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')";
    
    0 讨论(0)
  • 2021-01-17 07:06

    The values in the INSERT INTO query must be enclosed with single quotes ' not backticks and not a mixture of both. Backticks can only be used on the field and table name.

    $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')";
    

    Side note: your code is vulnerable to SQL Injection. Consider using a Prepared Statement with bound parameters instead of concatenating user input into the query.

    0 讨论(0)
提交回复
热议问题