Storing contents of a PHP array in a MySQL database

前端 未结 3 1796
清酒与你
清酒与你 2021-01-24 03:24

I am having trouble storing array contents in mysql I am using the code below

foreach($found_entry as $key => $sd) {
         echo \"$key => $sd 
3条回答
  •  执笔经年
    2021-01-24 03:40

    Your query syntax is wrong. Use SET instead of VALUES. Also, you probably don't need the foreach loop at all, as you are referencing both $sd[0] and $sd[11]. Try something like this:

    $query = sprintf("INSERT INTO
                 myTable
             SET
                 ID = '%s',
                 folder = NULL,
                 Tsi = '%s',
                 PT = 'NA'",
                 mysql_real_escape_string($found_entry[0]),
                 mysql_real_escape_string($found_entry[11])
             );
    
    mysql_query($query) or die(mysql_error());
    

提交回复
热议问题