
<?
//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:
<?
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.
Copyright © 2000-2010 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.