Independent
07-07-2008, 12:53 AM
Right, I was bored at the time of making this.
<?php
## CONNECTION TO DATABASE ##
mysql_connect("Your host", "Your username", "Your password"); // Connecting to the allocated server with the credentials inserted. (hostname, user, pass)
mysql_select_db("Your database"); // Selecting the database we'll connect too.
## VARIBLES ##
$table = "lolcopter"; // My table name is lolcopter.. Update this?
$field = "waffle"; // My field name is waffle.. Update this?
## CLEANER ##
function clean($s) { // Function start.
if (get_magic_quotes_gpc()) // Performing the clean, basically.
$s = stripslashes($s); // Stripping the slashes from the public seeing \"lol or so forth.
return mysql_real_escape_string($s); // Returning it..
} // Ending the function. As you see later in the code "clean($_POST..".
## FORM ## - Just to make our code cleaner, I've sectioned it.
if(!$_POST['submit']) {
echo "<form action=\"\" method=\"post\"><input name=\"roflcopter\" type=\"text\" /><input name=\"submit\" type=\"submit\" /></form>"; // Showing the form that will submit the data "roflcopter".
} // End of the !$_POST['Submit'] statement.
else { // If it has been posted, then the "else" will attempt to insert it into the database.
###############################################
$roflcopterpost = clean($_POST['roflcopter']); // We're cleaning the posted message, before it's inserted into the database.
mysql_query("INSERT INTO ". $table ." (". $field .") VALUES('$roflcopterpost') ") or die("Error executing your form."); // Now we're inserting it into the database.
echo "The data has been entered into the database."; // We're stating that it's been inserted.
################################################
}
?>
I've commented it as much as I could;
First, create a database;
Second, enter the connection details;
Third, Create a table & field named Waffle or something. (phpmyAdmin)?;
Forth, Insert the field name into " $field ".
This was a tutorial just to show you basically how it works, you can add-on bits, there are many useful tutorials all over the web.. some other links are listed below.
http://www.tizag.com/mysqlTutorial/
http://www.tizag.com/phpT/
http://www.techtuts.com/forums/index.php?showforum=5
Hope I've helped..
Calon.
<?php
## CONNECTION TO DATABASE ##
mysql_connect("Your host", "Your username", "Your password"); // Connecting to the allocated server with the credentials inserted. (hostname, user, pass)
mysql_select_db("Your database"); // Selecting the database we'll connect too.
## VARIBLES ##
$table = "lolcopter"; // My table name is lolcopter.. Update this?
$field = "waffle"; // My field name is waffle.. Update this?
## CLEANER ##
function clean($s) { // Function start.
if (get_magic_quotes_gpc()) // Performing the clean, basically.
$s = stripslashes($s); // Stripping the slashes from the public seeing \"lol or so forth.
return mysql_real_escape_string($s); // Returning it..
} // Ending the function. As you see later in the code "clean($_POST..".
## FORM ## - Just to make our code cleaner, I've sectioned it.
if(!$_POST['submit']) {
echo "<form action=\"\" method=\"post\"><input name=\"roflcopter\" type=\"text\" /><input name=\"submit\" type=\"submit\" /></form>"; // Showing the form that will submit the data "roflcopter".
} // End of the !$_POST['Submit'] statement.
else { // If it has been posted, then the "else" will attempt to insert it into the database.
###############################################
$roflcopterpost = clean($_POST['roflcopter']); // We're cleaning the posted message, before it's inserted into the database.
mysql_query("INSERT INTO ". $table ." (". $field .") VALUES('$roflcopterpost') ") or die("Error executing your form."); // Now we're inserting it into the database.
echo "The data has been entered into the database."; // We're stating that it's been inserted.
################################################
}
?>
I've commented it as much as I could;
First, create a database;
Second, enter the connection details;
Third, Create a table & field named Waffle or something. (phpmyAdmin)?;
Forth, Insert the field name into " $field ".
This was a tutorial just to show you basically how it works, you can add-on bits, there are many useful tutorials all over the web.. some other links are listed below.
http://www.tizag.com/mysqlTutorial/
http://www.tizag.com/phpT/
http://www.techtuts.com/forums/index.php?showforum=5
Hope I've helped..
Calon.