HTML Code:
<form name="frmreg" id="frmreg" method="post" action="save.php">
First name: <input type="text" name="firstname" /><br />
Last name: <input type="text" name="lastname" /><br />
<input type="submit" name="cmdregister" id="cmdregister" value="Register">
</form>
and on your save.php you'll have the following code..
PHP Code:
<?php
mysql_connect('hostname','user','password') or die(mysql_error());
mysql_select_db("databasename") or die(mysql_error());
if(isset(cmdregister)){
$sql = "insert into tablename(firstname,lastname) values('".$_post['firstname']."','".$_post['lastname']."')";
mysql_query($sql) or die(mysql_error());
echo '<script>alert("Successfully saved.");';
echo 'window.location=\'homepage.php\'; </script>';
}
?>
The form tags are on the page named homepage.php while the php codes are on the save.php. From the first page the user encodes the information. On the second page it proceeds from connecting to the database first then saving the information to the database. After saving I used the javascript to tell the user that the information has been successfully saved then it will be rerouted to the firstpage again.
Bookmarks