I'm trying to create a page where when a button is clicked a form displays. Then I want the user to input information into that form and click a submit button. I want this information to be submitted to a MySQL database without refreshing/leaving this page.
I've searched the internet and it seems like I have to use AJAX and jQuery to do this, but the problem is I don't know either of those at all. I've tried to follow examples and tutorials I've found on several sites, but I can't get any of them to work.
I have the form created already. The code for it is below.
<form name="classroom" method="post">
<fieldset>
<legend>Enter New MCP Information</legend>
<label for="date">Date:</label>
<input type="text" size="26" name="date" value="yyyy-mm-dd" onclick="this.value=''"onfocus="this.select()" onblur="this.value=!this.value?'yyyy-mm-dd':this.value;">
<p>
<label for="objective">Objective:</label>
<textarea name="objective" rows="3" cols="20" wrap="virtual"></textarea>
<p>
<label for="questions">Essential Questions:</label>
<textarea name="questions" rows="2" cols="20" wrap="virtual"></textarea>
<p>
<label for="criteria">Criteria for Success:</label>
<textarea name="criteria" rows="2" cols="20" wrap="virtual" onclick="this.value=''"onfocus="this.select()">Must be separated by commas.</textarea>
<p>
<label for="agenda">Agenda:</label>
<textarea name="agenda" rows="2" cols="20" wrap="virtual" onclick="this.value=''"onfocus="this.select()" >Must be separated by commas.</textarea>
<p class="submit"><input type="submit" class="submit" value="Submit"></p>
</fieldset>
</form>
The php script I'm using to write the form data is below. (I left out all the database connection and query info on purpose. It all works fine).
<?php
$day=addslashes($_POST['date']);
$objective=addslashes($_POST['objective']);
$questions=addslashes($_POST['questions']);
$criteria=addslashes($_POST['criteria']);
$agenda=addslashes($_POST['agenda']);
$connnect = mysql_connect("database","user","password");
if (!$connnect)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename") or die(mysql_error());
mysql_query("INSERT INTO mcp (Date, TPO, Questions, Criteria, Agenda)
VALUES ('$day', '$objective', '$questions', '$criteria', '$agenda')")
or die(mysql_error());
?>