Jump to content

lonesoac0

New Members
  • Posts

    6
  • Joined

  • Last visited

Everything posted by lonesoac0

  1. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.