Here i have a text area where i am going to put a value similar to this:
Sylhet,Sylhet,Sylhet,Khadim Nagar
Sylhet,Sylhet,Sylhet,Mogla Bazar
Sylhet,Sylhet,Sylhet,Mullar Gaon
each comma seperated string contains four value for four different field in database
in my database there are four field
bangladesh_info (Division,District,Thana,Union)
i want to capture the value from my text area and add three rows in their respective field .I wrote the following code where i used php pdo to connect and execute an insert command .I am getting
"new records created successfully"
but no value is getting inserted in the database .What might go wrong here? i am not getting any error !
<?php
if(isset($_POST['text']) && !empty($_POST['text'])){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myown";
try{
$conn = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password);
$stmt = $conn->prepare("INSERT INTO bangladesh_info (Division,District,Thana,Union)
VALUES (:division, :district, :thana,:union)");
$stmt->bindParam(':division', $division);
$stmt->bindParam(':district', $district);
$stmt->bindParam(':thana', $thana);
$stmt->bindParam(':union',$union);
$myarr=explode("\n",$_POST['text']);
foreach($myarr as $each){
list($div,$dis,$tha,$uni)=explode(',',$each);
echo $uni.'</br>';
$division=$div;
$district=$dis;
$thana=$tha;
$union=$uni;
$stmt->execute();
}
echo "New records created successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
}
?>
<html>
<body>
<form action='<?php echo $_SERVER["PHP_SELF"] ; ?>' method='POST' >
<textarea name='text' id='mytextarea'></textarea>
<input type='submit' value='submit' >
</form>
<script>
</script>
</body>
</html>