开发者

MYSQLI not putting data into the database

开发者 https://www.devze.com 2023-02-18 15:06 出处:网络
<?php $data = array( 0 => \'Natural Chlid 1\', 1 => \'Natural Chlid 2\', 2 => \'Natural Chlid 3\'
<?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));
    }

?>

this doesn't seem to send the data to the database the error im getting is:

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:开发者_StackOverflow社区0;s:15:\"Natural Chlid 1\";i:1;s:15:\"N' at line 1 


Use:

if (!$result) {
    printf("Error message: %s\n", mysqli_error($link));
}

to see the error message.

Edit:

Try this:

$result = mysqli_query($link, "INSERT INTO wills_children (will, children) VALUES (123, '$serialized')");


mysqli_error expect at least one parameter that is link to database.

Pass that parameter and problem will be solved

mysqli_error($link);

Do not put the quotes arround the column name instead you can use backquote to avoid reserved word error.

(`will`, `children`)
0

精彩评论

暂无评论...
验证码 换一张
取 消