don't post usernames/passwords in your code. replace these with **** for your own security.
Some notes included:
PHP Code:
<?php
$host="********"; // Host name
$username="********"; // Mysql username
$password="********"; // Mysql password
$db_name="database_test"; // Database name
$tbl_name="signups"; // Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// THIS IS VERY UNSAFE!!
/*
// Get values from form
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$total_payable=$_POST['total_payable'];
*/
// ALWAYS SANITIZE USER-SUBMITTED DATA BEFORE INSERTING IT INTO YOUR DATABASE!
// You might want to actually validate the submitted data
// (make sure it _is_ the data you want, is correctly formatted, etc.),
// but at the very least, you need to make sure you are not injecting malicious code.
// Get values from form and sanitize for database insertion
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$total_payable = mysql_real_escape_string($_POST['total_payable']);
// note time of submission
$reg_submit_date = time();
// (this creates a Unix Timestamp.
// it's the quickest, most reliable way to store the time of submission,
// but will need to be formatted (e.g., using the date() function)
// to be made human-readable.)
// Insert data into mysql
// It's good practice to `backtick` your mysql table and column names
// no, `backticks` are _not_ 'quotes'
$sql="INSERT INTO `$tbl_name`(`firstname`, `lastname`, `total_payable`, `reg_submit_date`)VALUES('$firstname', '$lastname', '$total_payable', '$reg_submit_date')";
$result=mysql_query($sql);
// if successfully insert data into database, displays message "Successful".
if($result){
echo "Successful!";
echo "<BR>";
}
else {
echo "Error occured";
}
// close connection
mysql_close();
?>
Bookmarks