I have a project that I am using OpenJS grid with a Bootstrap modal to POST rows to the table. I have used this basic outline before and it has always worked. But now with using these new elemnts I cant POST to the database. The form looks like:
<!-- Add Message Form--------------------------------------------------------------------------->
<div class="container">
<h2>Memo</h2>
<form role="form" action="add.php" method="post">
<div class="form-group">
<label for="from">From:</label>
<input type="text" class="form-control" id="from" name="from_val" placeholder="Message From">
</div>
<div class="form-group">
<label for="note">Enter Message:</label>
<input type="textarea" class="form-control" rows="5" id="note" name="note_val" placeholder="Enter Your Message">
</div>
<div class="form-group">
<label for="date_entered">Enter Date:</label>
<input type="date" class="form-control" id="date_entered" name="date_val" placeholder="yyyy/mm/dd">
</div>
<div class="form-group">
<label for="time_entered">Enter Time:</label>
<input type="text" class="form-control" id="time_entered" name="time_val" placeholder="hh:mm:ss">
</div>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" id="newData" class="btn btn-primary btn-md">Submit</button>
</form>
</div>
<!-- End Form ------------------------------------------------------------------------------------>
</div>
The php script is:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
include ("dbinfo.inc.php"); //include login info file
//Start a PDO session to insert the form data into the MySQL Table
try
{
$conn=new PDO($dsn, $username,$password);
echo 'Connected to MySQL Ok.';
}
catch (PDOException $e)
{
$error_message=$e->getMessage();
echo "<h1>Resource Unavailable. Please Contact the System Administrator</h1>";
}
$from=$_POST['from_val'];
$note=$_POST['note_val'];
$date=$_POST['date_val'];
$time=$_POST['time_val'];
print_r ($_POST);
if ($from !='') { $stmt = $conn->prepare("INSERT INTO Messages SET from = :from, note = :note, date = :date, time = :time");
$stmt->execute(array(
':from' => $from,
':note' => $note,
':date' => $date,
':time' => $time));
echo '<br /n>';
echo '<br /n>';
echo '<h3><center><b>Added Record Successfully</b></center></h3>';
}
else {
echo '<br /n>';
echo '<br /n>';
echo 'Attention. You Did Not Enter a Message. Please enter the Message<br /n>';
echo 'At a Minimum..';
}
?>
I checked the php and it validates ok. On the add.php page I get this after adding a record:
Connected to MySQL Ok.Array
(
[from_val] => alan
[note_val] => test message.
[date_val] => 2015/03/22
[time_val] => 12:00:10
)
<br /n><br /n><h3><center><b>Added Record Successfully</b></center></h3>
This does not look right to me. I dont remember POST info in this format before when I was troubleshooting issues.