|
Here is what we have to write in English for the processing: If submit is hit, then connect to the database Insert the values into the correct database. 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: If submit is NOT hit, then make the form with the action as this file itself. 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. 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
|