Home arrow PHP Tutorials

Translate This Website
Sunday, 07 September 2008
Web Development
Request a Quote
Script Categories
RSS Media Grabber Funny Videos & Pictures Life Stories (Flash) Video Search & Download Video Downloader Script Country on Sale Advanced Polls Phone Upload/SMS Scripts PhotoCube Script SlideShow Creation Script Make Confessions Scripts Guitar Tabs Scripts Create Custom Smiley Script Short URLs & Subdomains Hot Or Not Game Scripts Put your text on images Watermark & Image Hosting Joomla Components Low Cost Scripts
Partners
WEBSITE TRAFFIC
Pissed Customers
Credit Cards
Broadband Tweaks & Info
eBay Sniping Software
Custom Programming
Scripts and Stuffs
Hot php scripts
Add your scripts
Script Search
php scripts directory
script heaven
the cgi site
Scripts
Software Development
Free Icons
SEO Services


Add a Row to mySQL Print E-mail

Here is what we have to write in English for the processing:

  1. If submit is hit, then connect to the database

  2. Insert the values into the correct database.

  3. Get a conformation that it has been uploaded

Here it is in PHP:

<?
//initilize PHP

if($_POST['submit']) //If submit is hit
{
//then connect as user
//change user and password to your mySQL name and password
mysql_connect("localhost","user","password");

//select which database you want to edit
mysql_select_db("spoono_news");

//convert all the posts to variables:
$title = $_POST['title'];
$message = $_POST['message'];
$who = $_POST['who'];
$date = $_POST['date'];
$time = $_POST['time'];

//Insert the values into the correct database with the right fields
//mysql table = news
//table columns = id, title, message, who, date, time
//post variables = $title, $message, '$who, $date, $time
$result=MYSQL_QUERY("INSERT INTO news (id,title,message,who,date,time)".
"VALUES ('NULL', '$title', '$message', '$who', '$date', '$time')");

//confirm
echo "Query Finished";
}
?>

And that is basically all the code we have to write for the processing. Now the hard part, writing the form, which isn't really as hard as it seems. Here is what we have to write in English for the Form:

  1. If submit is NOT hit, then make the form with the action as this file itself.

  2. Create an HTML table and plug in all the information. Make sure that the "name" section of each input matches up with the processing code. For example, the "$_POST['title']" on the processing up above means one of the fields down here must me named title. The ID is left blank because its Auto-Increment.

  3. Make the Submit button, so the If-Then on this runs properly.

I hope you can understand HTML forms, as the code is fairly basic. All forms are inputs, the name field becomes the PHP post variable with a value of the value field. Here is the HTML and PHP:

<?
else
{
// close php so we can put in our code
?>
<form method="post" action="add.php">
<TABLE>
<TR>
<TD>Title:</TD>
<TD><INPUT TYPE='TEXT' NAME='title' VALUE='Random Update' size=60></TD>
</TR>
<TR>
<TD>Message:</TD>
<TD><INPUT TYPE='TEXT' NAME='message' VALUE='' size=60></TD>
</TR><br>
<TR>
<TD>name_upper:</TD>
<TD>
<SELECT NAME='who'>
<OPTION VALUE='Akash'>Akash
<OPTION VALUE='Brian'>Brian
</SELECT>
</TD>
</TR>
<TR>
<TD>date:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of date -->
<INPUT TYPE='TEXT' NAME='date' VALUE='<? echo date("M.j.y"); ?>' size=60>
</TD>
</TR>
<TR>
<TD>time:</TD>
<TD>
<!-- You can use PHP functions to automatically get the value of time -->
<INPUT TYPE='TEXT' NAME='time' VALUE='<? echo date("g:i a"); ?>' size=60>
</TD>
</TR>
<TR>
<TD></TD><br>
<TD><INPUT TYPE="submit" name="submit" value="submit"></TD>
</TR>
</TABLE>
</form>

<?
} //close the else statement
?>

The name is title, which matches up with $title at the top, and when you run the script, the default text is going to be post on the board and ask for help and we'll try to help you out. You can see my code that I worked on and made sure worked by right clicking and saving delete.txt.

Credit: www.spoono.com 





Reddit!Del.icio.us!Facebook!Slashdot!Netscape!Technorati!StumbleUpon!Newsvine!Furl!Yahoo!Ma.gnolia!Free social bookmarking plugins and extensions for Joomla! websites!
 
< Prev   Next >
Services
Script Installation
Hosting
Free Image Hosting
PageRank Checker
Login Form
On Sale
RSS Media Grabber - Get 100s of Videos
RSS Media Grabber - Get 100s of Videos
$129.00
$79.00
You Save: $50.00
Add to Cart
Home Announcements Support Newsletter Forum PHP Articles PHP Tutorials Scripts FAQs Free Scripts Links Contacts
Copyrighted © 2008 phppod.com