You still don't validate the fields being set or not. You can add in the else statements in case you want something specific to go into the data if the field isn't set. More importantly, you don't sanitize your input. This can lead to SQL injections, which can lead to exposed data and data that can be tampered with.
// DB connection
$con = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
// Validate input fields
if (isset($_SESSON['user_id']))
$user_id = $_SESSON['user_id'];
if (isset($_POST['Date']))
$Date = $_POST['Date'];
if (isset($_POST['Time']))
$Time = $_POST['Time'];
if (isset($_POST['Amonia']))
$Amonia = $_POST['Amonia'];
if (isset($_POST['Nitrite']))
$Nitrite = $_POST['Nitrite'];
if (isset($_POST['Nitrate']))
$Nitrate = $_POST['Nitrate'];
if (isset($_POST['PH']))
$PH = $_POST['PH'];
if (isset($_POST['Salinity']))
$Salinity = $_POST['Salinity'];
// Assumed misspelled and fixed
if (isset($_POST['Temperature']))
$Temperature = $_POST['Temperature'];
// Attempts DB insert
try {
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "
INSERT INTO post (user_id, Date, Time, Amonia, Nitrite, Nitrate, PH, , Salinity, Temperature)
VALUE (:user_id, :Date, :Time, :Amonia, :Nitrite, :Nitrate, :PH, :Salinity, :Temperature)
";
// Makes data nice for the DB.
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':Date', $Date);
$stmt->bindParam(':Time', $Time);
$stmt->bindParam(':Amonia', $Amonia);
$stmt->bindParam(':Nitrite', $Nitrite);
$stmt->bindParam(':Nitrate', $Nitrate);
$stmt->bindParam(':PH', $PH);
$stmt->bindParam(':Salinity', $Salinity);
$stmt->bindParam(':Temperature', $Temperature);
$stmt->execute();
echo "1 record added";
}
// Insert failed.
catch (PDOExecption $e) {
echo $e->getMessage();
}
See more here.
http://bobby-tables.com/
http://www.php.net/manual/en/intro.pdo.php
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/