I collect data from the form and throw it into the database. Some of the data just needs to be serialized. But here a trouble, mysql throws an error ... I can not understand that it does not like in the serialized data

$prop = serialize($elements['prop']); $prop = addslashes($prop); $sql = 'insert into iblocks(name,code,desct,serialize) values('.$elements['name'].','.$elements['code'].','.$elements['desc'].','.$prop.')'; 


corresponds to your MySQL server version for the right syntax to use near ':2:{i:0;a:5:{s:4:\"name\";s:3:\"sdf\";s:4:\"code\";s:3:\"sfd\";s:4:\"type\";s:3:' at line 1

    2 answers 2

    Take the query string in double quotes. And the lines in the query is better framed with quotes. Since you are not using placeholders.

      $sql = "insert into iblocks(name,code,desct,serialize) values('".$elements['name']."','" .$elements['code']."','".$elements['desc']."','".$prop."')"; 
    • thanks, worked - JIOnOCTb

    Better yet, do this with the variables that make up the query.

    $prop = mysql_real_escape_string($prop);

    • Better yet, use PDO and placeholders ( mysql_* deprecated, mysql_* functions). Tea does not live in the 90s. - drdaeman