如何将这些数组值存储到数据库(单独的行)?

时间:2014-02-15 05:00:24

标签: php mysql arrays

save.php

<?php
include('config.php');

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

$strexplode = $_POST['name'];
$separator = " ";
$arr = explode($separator,$strexplode);

print_r($arr);

try
{
    $stmt = $conn->prepare("INSERT INTO sample NAME ( category ) VALUES ( ? )");
    $conn->errorInfo();
    $stmt->bindValue('1', HOW TO PASS THAT $arr HERE , PDO::PARAM_STR);
    $stmt->execute();
}
catch(PDOException $e)
{
    'Error : ' .$e->getMessage();
}
if($stmt)
{
    echo "Success";
}
else
{
    echo "Error";
}
?>

mainpage.php

<form method="post" action="save.php">
    <input type="text" name="name" value="" />
    <input name="storetodb" type="submit" value="Store"/>
</form>

如果用户在我的数据库中输入像“rahul sharad dravid”这样的输入文本字段中的值,我希望这些值应该存储在单独的行中。如何将这些数组值存储到数据库(单独的行)?

| CATEGORY
| rahul
| sharad
| dravid     

0 个答案:

没有答案
相关问题