我尝试过使用单引号和$ session变量的大量语法试验,现在我决定将会话变量放在常规变量中,以减少语法复杂性。
$conn = mysql_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysql_error());
}
if (!mysql_select_db($dbname)) {
die('Could not select database: ' . mysql_error());
}
$this_email = $_SESSION['email'];
$this_password = $_SESSION['pw'];
$this_number = $_SESSION['phone'];
$sql = mysql_query("INSERT INTO user_accounts(Email, Password, Phone#) VALUES ('$this_email','$this_password','$this_number')");
if (!$sql) {
echo mysql_error();
}
mysql_close($conn);
这是我得到的错误:
您的SQL语法有错误;查看与您的MariaDB服务器版本对应的手册,以获得在''附近使用的正确语法。在第1行
答案 0 :(得分:2)
列名可能包含INSERT INTO user_accounts(Email, Password, `Phone#`)
。所有其他角色都需要加入反叛。
http://dev.mysql.com/doc/refman/5.7/en/identifiers.html
所以试试:
data
您还应该更新驱动程序并使用预准备语句。
答案 1 :(得分:1)
因为#
中有一个特殊字符(<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.1-1</version>
</dependency>
<dependency>
<groupId>com.github.fge</groupId>
<artifactId>json-patch</artifactId>
<version>1.9</version>
</dependency>
public class Json {
static class Patch {
enum Op {
ADD, REMOVE, REPLACE;
};
private final Op op;
private final String path;
private final String value;
@JsonCreator
public Patch(//
@JsonProperty("op") String op, //
@JsonProperty("path") String path, //
@JsonProperty("value") String value) {
this.op = Op.valueOf(op.toUpperCase());
this.path = path;
this.value = value;
}
@Override
public String toString() {
return "Patch [op=" + op + ", path=" + path + ", value=" + value + "]";
}
}
public static void main(String[] args) throws Exception {
// jsons to compare
String json1 = "{}";
String json2 = "{\"name\":\"Sean\", \"state\":\"Colorado\"}";
// convert jsons to JsonNode
JsonNode json1Node = mapper.readTree(json1);
JsonNode json2Node = mapper.readTree(json2);
// create Supplier<InputStream>
final String strDiff = JsonDiff.asJson(json1Node, json2Node).toString();
Supplier<InputStream> diffs = () -> new ByteArrayInputStream(strDiff.getBytes());
MappingIterator<Patch> iterator = new ObjectMapper()//
.readerFor(Patch.class) //
.readValues(diffs.get());
List<Patch> patches = new ArrayList<>();
while (iterator.hasNext()) {
patches.add(iterator.next());
}
System.out.println(patches);
}
}
),你需要用反引号来写它!
此外,我建议您使用PDO或mysqli lib以及预处理语句,因为不推荐使用mysql库。