我的SQL语法错误让我反复头痛

时间:2018-02-18 18:59:39

标签: php sql

登录时出现问题。您的SQL语法有错误;

  

查看与您的MariaDB服务器版本相对应的手册,以获得正确的语法,以便在'方式',' ENGLAND',' sn66er',&#39附近使用;主人',' 6个月' 1793321653','','州','' ;在第1行

你好,PHP的新手,我正在努力尝试运行的代码,我得到了这个错误。拜托,我错过了什么?我检查了其他相关问题并尝试了一切但没有成功:

$query = "INSERT INTO users  (Title, username, password, marital_status,
dependents, name, lastname, email, loan_purpose, employment_status,
employer_name, work_address, work_region, work_postcode, work_mobile,
employment_type, time_employer, payment_frequency, wages_paid_into_account, 
othermonthly_income, rent_mortgages, creditcards_loans, 
othermonthly_expenses, account_name, bank_name, account_no, sortcode,
yearswith_bank, heard_about_us, address, region, postcode, residential_type,
time_address, mobile, landline, county, birthdate, income, nextpaydate, Loanamount, Terms, Monthlyrepayment, Totalrepayment, Interest, gender)
VALUES ('$title', '$username',  '$password', '$maritalstatus', '$dependant',
'$name', '$lastname', '$email', '$loanPurpose', '$employmentStatus', 
'$employerName', '$employerAddress', '$employerRegion', '$workpostcode', 
'$workphone', '$employmentType', '$employmentLength', '$paymentFrequency',
'$howYouGetPaid', '$otherIncome', '$rent_mortgage',
'$creditCard_loansExpenses', '$otherMonthlyExpenses', '$accountName',
'$bankName', '$accountNumber', '$sortCode', '$accountLength',
'$hearAboutUs',  $address', '$region', '$postcode', '$tenancyType', 
'$timeatAddress', '$mobilenumber', '$landline', '$county', '$birth',
'$income', '$nextPay', '$loanamount', '$terms', '$monthlyrepayment',
'$totalrepayment', '$interest', '$gender')";


if (mysqli_query($connection, $query)){     
    $_SESSION["username"] =$username; 
    echo " Successfully logged in";
    header("location: login.php");
}
    //create a variable to see if it went through
    // $result =  mysqli_query($connection,  $query ); // assign variable
else{

    die("<p> There is a problem signing you up.</p>" . mysqli_error($connection));

}

2 个答案:

答案 0 :(得分:0)

在$ address

之前缺少单引号
$query = "INSERT INTO users (Title, username, password, marital_status, dependents,
             name, lastname, email, loan_purpose, employment_status, employer_name, 
             work_address, work_region, work_postcode, work_mobile, employment_type, 
             time_employer, payment_frequency, wages_paid_into_account,
              othermonthly_income, rent_mortgages, creditcards_loans, 
              othermonthly_expenses, account_name, bank_name, account_no, 
              sortcode, yearswith_bank, heard_about_us, address, region, 
              postcode, residential_type, time_address, mobile, landline, 
              county, birthdate, income, nextpaydate, Loanamount, Terms, 
              Monthlyrepayment, Totalrepayment, Interest, gender) 
      VALUES ('$title', '$username', '$password', '$maritalstatus', '$dependant', 
          '$name', '$lastname', '$email', '$loanPurpose', '$employmentStatus', 
          '$employerName',  '$employerAddress', '$employerRegion', '$workpostcode', '$workphone', 
          '$employmentType',  '$employmentLength', '$paymentFrequency', '$howYouGetPaid', '$otherIncome', 
          '$rent_mortgage', '$creditCard_loansExpenses', '$otherMonthlyExpenses', '$accountName', 
          '$bankName', '$accountNumber', '$sortCode', '$accountLength', '$hearAboutUs', '$address', 
          '$region', '$postcode', '$tenancyType', '$timeatAddress', '$mobilenumber',
           '$landline', '$county', '$birth', '$income', '$nextPay', '$loanamount', '$terms', 
       '$monthlyrepayment', '$totalrepayment', '$interest', '$gender')";

答案 1 :(得分:0)

你在$ address之前错过了单引号。

  

INSERT INTO用户   (标题,   用户名,   密码,   婚姻状况,   家属,   名称,   姓,   电子邮件,   loan_purpose,   就业状况,   employer_name,   work_address,   work_region,   work_postcode,   work_mobile,   雇佣类型,   time_employer,   payment_frequency,   wages_paid_into_account,   othermonthly_income,   rent_mortgages,   creditcards_loans,   othermonthly_expenses,   用户名,   银行名,   户口号码,   SORTCODE,   yearswith_bank,   heard_about_us,   地址,   区域,   邮编,   residential_type,   time_address,   移动,   座机,   县,   生日,   收入,   nextpaydate,   贷款额度,   方面,   monthlyrepayment,   totalrepayment,   利益,   性别)   VALUES( '$标题',   '$用户名',   '$密码',   '$ maritalstatus',   '$依赖',   '$名',   '$姓氏',   '$电子邮件',   '$ loanPurpose',   '$ employmentStatus',   '$ employerName',   '$ employerAddress',   '$ employerRegion',   '$ workpostcode',   '$办公电话',   '$ employmentType',   '$ employmentLength',   '$ paymentFrequency',   '$ howYouGetPaid',   '$ otherIncome',   '$ rent_mortgage',   '$ creditCard_loansExpenses',   '$ otherMonthlyExpenses',   '$帐户名',   '$ BANKNAME',   '$使用accountNumber',   '$ SORTCODE',   '$ accountLength',   '$ hearAboutUs',   '$地址',   '$区',   '$邮编',   '$ tenancyType',   '$ timeatAddress',   '$移动电话号码',   '$座机',   '$县',   '$诞生',   '$收入',   '$ NextPay让'   '$ loanamount',   '$术语',   '$ monthlyrepayment',   '$ totalrepayment',   '$兴趣',   '$性别')