Here's what I am trying to do... When a user clicks the submit button in the form (I am using the jQuery Form plugin which is working fine), this should save the content of the textarea in the database. The JavaScript alert should show the last updated ID in the database. But for some reason, although the data is being saved, the JavaScript isn't working, not sure why.
HTML form (index.html):
<form action="submit.php" method="post" id="myForm">
<input type="submit" name="submit" value="Submit"/>
<div id="edit-box">
<textarea id="editor" name="editor"><?php echo $content; ?></textarea>
</div>
</form>
Submit form (submit.php):
<?
// connect to the database
include('connect-db.php');
// get form data, making sure it is valid
$submit_date = date("Ymd");
$content = mysql_real_escape_string(htmlspecialchars($_POST['editor']));
$ip_address = getRealIPAddress(); //$_SERVER['REMOTE_ADDR'];
// check to make sure both fields are entered
if ($content != '') {
// save the data to the database
mysql_query("INSERT source SET submit_date='$submit_date', ip='$ip_address', content='$content'");
or die(mysql_error());
$lastrow = mysql_query("SELECT MAX(id) FROM source");
echo '<script type="text/javascript"> alert("' . echo $lastrow . '");</script>';
}
?>
Also, do I have to close the connection everytime?