Hello all,
I am interested in creating a very simple form that onclick it adds a new record to my table. Can I accomplish this task with the basic code that I have on the line with "Button Type" ? I am totally open to different methods too.
<?php
$servername = "localhost";
$username = "bleh";
$password = "password";
$dbname = "logger";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception.
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// sql to select last record inserted.
foreach($conn->query('select status from comins_and_goins order by id DESC limit 1') as $row) {
$var = $row['status'];
}
if ($var == 1) {
echo "You are going to work or somewhere else for a while.";
echo '<button type="button" onclick="MySQL query that inserts record.">Click Me</button>';
}
else{
echo "You are back home! I missed you!";
}
}
catch (PDOExecption $e)
{
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
On a side note, I also feel that I need to acknowledge the foreach statement is a little redundant for the MySQL syntax that I am executing on the same line. I figured, it works and I just want my new toy operational ASAP.