使用php插入sql数据库时出错 [英] Error when inserting into sql database using php

查看:68
本文介绍了使用php插入sql数据库时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有MySQL插入查询的程序:

I have a program with a MySQL insert query:

        $sql = "INSERT INTO people (person_id, name, username, password, email, salt)
                VALUES ($person_id, $name, $username, $password, $email, $salt)";
        if ($con->query($sql) === TRUE) {
            successful();
        } else {
            unsuccessful("Error: " . $sql . "<br>" . $con->error);
        }

运行代码时出现此错误:

When I run the code I get this error:

Error: INSERT INTO people (person_id, name, username, password, email, salt) VALUES (2, Tom Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, tom@tommy.com, eb694539989fda2e17f79e70fb306f8911c3dee5)
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 'Jack, tjack95, 8a01fc598a676a249c5844bd3baf4f4d83cecdf2, tom@tommy.com, eb69' at line 2

sql插入对我来说似乎完全正常.有什么问题吗?

The sql insert looks completely fine to me. What is the problem?

推荐答案

您在字符串值周围缺少引号:

You're missing quotes around your string values:

$sql = "INSERT INTO people (person_id, name, username, password, email, salt)
            VALUES ($person_id, '$name', '$username', '$password', '$email', '$salt')";

这篇关于使用php插入sql数据库时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆