drt3751 2016-01-12 14:09
浏览 58
已采纳

MySQL插入错误

It's pretty much one of my first times working with MYSQL, and I can't seem to fix this one error I keep getting. I'm trying to store data to a table which has an auto_increment on its id (first column). The error I keep getting is this:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'voorletters ='asd', tussenvoegsel ='', achternaam ='', roepnaam ='', adres ='', ' at line 1"

I just filled the textboxes with a little bit of rubish, there are no columns that require data either. Here is the code I use:

if(isset($_POST['save']))
{   
    $voorletters = $_POST['voorletters'];
    $tussenvoegsel = $_POST['tussenvoegsel'];
    $achternaam = $_POST['achternaam'];
    $roepnaam = $_POST['roepnaam'];
    $adres = $_POST['adres'];
    $postcode = $_POST['postcode'];
    $plaats = $_POST['plaats'];
    $geslacht = $_POST['geslacht'];
    $emailadres = $_POST['emailadres'];
    $telefoonnummer = $_POST['telefoonnummer'];
    $mobielenummer = $_POST['mobielenummer'];
    $geboortedatum = $_POST['geboortedatum'];
    $bsn = $_POST['bsn'];

    mysql_query("INSERT INTO `naw` "
            . "voorletters ='$voorletters', "
            . "tussenvoegsel ='$tussenvoegsel', "
            . "achternaam ='$achternaam', "
            . "roepnaam ='$roepnaam', "
            . "adres ='$adres', "
            . "postcode ='$postcode', "
            . "plaats ='$plaats', "
            . "geslacht ='$geslacht', "
            . "emailadres ='$emailadres', "
            . "telefoonnummer ='$telefoonnummer', "
            . "mobielenummer ='$mobielenummer', "
            . "geboortedatum ='$geboortedatum', "
            . "bsn ='$bsn' "
            . "WHERE id = '$id'")
            or die(mysql_error()); 

If this isn't enough information, please tell me. I've tried a lot of things, but I can't seem to figure it out.

  • 写回答

4条回答 默认 最新

  • douna1941 2016-01-12 14:11
    关注

    You mix up insert and update syntax. Replace

    INSERT INTO `naw` voorletters ='$voorletters'...
    

    with

    UPDATE `naw` set voorletters ='$voorletters'....
    

    And you should really use Prepared Statements to avoid syntax errors and SQL injections due to user input.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法