<?php
$data = array(
0 => 'Natural Chlid 1',
1 => 'Natural Chlid 2',
2 => 'Natural Chlid 3'
);
$link = mysqli_connect('localhost', 'root', '', 'mutli_page_form');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$serialized = mysqli_real_escape_string($link, serialize($data));
$result = mysqli_query($link, "INSERT INTO wills_children ('will', 'children') VALUES (123, '$serialized')");
if (!$result) {
printf("Error message: %s\n", mysqli_error($link));
}
?>
这似乎没有将数据发送到数据库,我得到的错误是:
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 ''will', 'children') VALUES (123, 'a:3:{i:0;s:15:\"Natural Chlid 1\";i:1;s:15:\"N' at line 1
答案 0 :(得分:1)
使用:
if (!$result) {
printf("Error message: %s\n", mysqli_error($link));
}
查看错误消息。
编辑:
试试这个:
$result = mysqli_query($link, "INSERT INTO wills_children (will, children) VALUES (123, '$serialized')");
答案 1 :(得分:1)
mysqli_error
期望至少有一个链接到数据库的参数。
传递该参数并解决问题
mysqli_error($link);
不要在列名称周围加上引号,而是可以使用反引号来避免保留字错误。
(`will`, `children`)