|
| Web Hosting Deals | Holiday Logo Design | Webcam Chat | Website Header Templates | Register domain | Search Engine Optimisation | Web Hosting |
|
|||||||
| PHP / Perl / Java / JavaScript / CGI Tutorials PHP / Perl / Java / JavaScript / CGI Tutorials Please do not use this Forum to advertise your site or to link to tutorials. |
![]() |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
||||
|
The CMS (#3) PHP
Ok, so we are now onto part 3 of our tutorial!
So in this we are going to do: add-news.php This is going to be quite a complicated one, so make sure that your watching! Let's start off with creating the database tables that we need! First thing you need to do is edit your install.php and add the following code, or if your not using an installer place the following code into whatever your using. Code:
CREATE TABLE `news` ( `ID` INT( 11 ) NOT NULL AUTO_INCREMENT , `title` VARCHAR( 250 ) NOT NULL , `author` VARCHAR( 250 ) NOT NULL , `date` VARCHAR( 250 ) NOT NULL , `content` TEXT NOT NULL , PRIMARY KEY ( `ID` ) ) TYPE = MYISAM Or your install.php should now look like this: PHP Code:
PHP Code:
First few lines our are security to make sure no un autorised users can add news So the first line you won't know is this: $thedate = date('n/j/Y'); - Now this is the PHP date function, this is usefull, this gets the server date! If you want to know more about this function, because i am not going to explain it in this tutorial go here they explain it nicely ![]() if($_POST['submit']) { - You know that to post a form we do this code Code:
<input type="submit" name="Submit" value="Submit"> "If sumit has been posted then do the following:" $title = $_POST['title']; $author = $_POST['author']; $content = $_POST['content']; - Getting the information from the title, author and content fields. $title = htmlspecialchars($title); $author = htmlspecialchars($author); Now this is somthing you will use allot in forms, this means that any special charicters such as <iframe or stuff like that is removed, so that it won't show it. Read more about them here $query = "INSERT INTO news (ID, title, author, date, content) VALUES ('', '$title', '$author', '$date', '$content')"; So I am going to do the code to speach thing again: "In the variable $query insert into the table news into the rows called ID, title, author, date & content the following variables '' nothing, because id is auto increment we don't have to add anything then the variable $title into the table row, then author into its corresponding row, and so on and so on!" mysql_query($query) or die(mysql_error()); - Actually runs the above query, or it gives you an error. echo "<center><strong>News item added!</strong></center>"; - tells the user their news is added. The only line you may not know in the form code is this bit PHP Code:
You remember at the top we put: if($_POST['submit']) { Right look at the bottom of our HTML code. <input type="submit" name="submit" value="Submit" /> :O:O:O:O:O Shocking!!! That means that its only going to execute that PHP code if somoene has clicked submit!!!! Clever stufff egh.. <?php } ?> - Just ending our security So there we go, in a few hours i will post the follow up tutorial for the edit-news.php which include del function! Watch out for that peeps Base (No up to the minute fule included in this post, because i am posting the next tutorial very soon, and am making some changes so no point!)
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png PointServ.co.uk - One of the UK's cheapest webhosting companies. Last edited by Base; 03-31-2007 at 06:59 AM. |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|