1

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>

If user enter the value in input textfield like this "rahul sharad dravid" in my database i want these values should be stored in separate row. How do i store these array values into database (separate row)?

| CATEGORY
| rahul
| sharad
| dravid     
Karuppiah RK
  • 3,894
  • 9
  • 40
  • 80
  • 3
    `$stmt = prepare(...); bind_variables(); foreach($arr as $name) { $stmt->execute($name); }` – Marc B Feb 15 '14 at 05:02
  • Or you could insert them all with [a single query](http://stackoverflow.com/questions/1176352/pdo-prepared-inserts-multiple-rows-in-single-query). – quickshiftin Feb 15 '14 at 05:17

0 Answers0