Web Hosting Deals Holiday Logo Design Webcam Chat Website Header Templates Register domain Search Engine Optimisation Web Hosting
Go Back   Talk Mania Forum > Tutorials > PHP / Perl / Java / JavaScript / CGI Tutorials

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.

 Image
Buy Sell Downloads

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-04-2007, 09:05 PM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
The CMS (#8) PHP

Ok so as promised this is one of the last CMS tutorials.

All we have left after this is the template system, and allthough thats going to be a fun one, and going to be a lengthly one, we have but a few tutorials left together!

As allways

Start off with adding to our installer.

If your not using our PHP installer, and your using somthing else, then you will need this code:

Code:
CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
`time` text NOT NULL,
PRIMARY KEY  (`id`)
);
If your using our PHP installer then add the following code to our install.php

PHP Code:
mysql_query("CREATE TABLE `shoutbox` (
`id` int(11) NOT NULL auto_increment,
`name` text NOT NULL,
`message` longtext NOT NULL,
`time` text NOT NULL,
PRIMARY KEY  (`id`)
);"
)
 or die(
mysql_error());  
    echo 
"Shoutbox table created";
    echo 
"<br><br>"
Ok, so now we have the tables in place, we need to slap down some code.

Now shoutboxes are pretty much exactly the same as guestbooks.

So if you have read my guestbook tutorial, none of this will shock you.

PHP Code:
<?php
include("../../includes/connect.php");
if(
$_POST['submit']) {

$name $_POST['name'];
$message $_POST['message'];

   
//use the PHP date function for the time
   
$timedate("h:ia d/j/y");
   
   
// inserting it into the shoutbox table which we made in the mysql statements before
   
$result=MYSQL_QUERY("INSERT INTO shoutbox (id,name,message,time)".
      
"VALUES ('','$name', '$message','$time')");
} else {

$result mysql_query("select * from shoutbox order by id desc limit 5");

//the while loop
while($row=mysql_fetch_array($result))
{        
   
//getting each variable from the table
   
echo $row['name'];
   echo 
"<br>";
   echo 
$row['message'];
   echo 
"<br>";
   echo 
"<br>";
}

?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<INPUT TYPE='TEXT' value='Name' NAME='name' SIZE=30 maxlength='100'>
<br>
<textarea name="message" cols="30" rows="5">message</textarea>
<br>
<input type="submit" name="submit" value="submit">
</form>
<?php ?>
As allways in these tutorials aparently, i have repeatedly gone over this code before.

$time= date("h:ia d/j/y");

Gets the time/date

$result = mysql_query("select * from shoutbox order by id desc limit 5");

Selects all from the shoutbox with the limit of 5, orderd by ID.

echo $row['name'];
echo "<br>";
echo "$row['message'];
echo "<br>";
echo "<br>";

Is repeated untill the table is empty

Ok, so save that in this directory:

http://www.yourdomain.com/admin/shoutbox/index.php

save it as that.

i.e. save it as the file index.php in your shoutbox directory.

Right then, now we move onto our edit-shoutbox.php inside our admin directory.

PHP Code:
<?php
session_start
();
if(
$login_username=="") {
Header("Location: login.php");
} else {

include(
"../includes/connect.php");

// including the connect file for the database.

// If the user has posted to edit then:
if($_POST['edit']) {

// Get variables.
$id $_POST['id'];
$name $_POST['name'];
$message $_POST['message'];


// Run the re-edited stuff through HTML charicters
$name htmlspecialchars($name);
$comment htmlspecialchars($comment);

// Put our query into a variable.

$query "UPDATE shoutbox SET name = '$name', message = '$message' WHERE ID = '$id'";

$result mysql_query($query) or die(mysql_error());
echo 
"<center><strong>Shoutbox post modified.</strong></center>";
// Otherwise
} else {

$query "SELECT * FROM shoutbox ORDER BY ID DESC";

$result mysql_query($query) or die(mysql_error());
while (
$row mysql_fetch_array($result)) {
extract($row);
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table align="center">
<tr>
  <td align="right">Name:</td>
  <td><input name="name" type="text" id="name" value="<?php echo "$name"?>" maxlength="250" /></td></tr>
<tr>
  <td align="right">Comment:</td><td><textarea name="message" cols="50" rows="10" id="message"><?php echo "$message"?></textarea></td></tr>

<tr><td> </td><td><input type="hidden" name="id" value="<?php echo "$id"?>" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" />
    <input name="del" type="submit" id="del" value="Delete" /></td></tr>
</table>
</form>

<?php
}

if(
$_POST['del']) {
$query "DELETE FROM shoutbox WHERE ID = '$id'";
//Execute the query.
$result mysql_query($query) or die(mysql_error());
echo 
"The post has been deleted";
header("Refresh: 2; edit-shoutbox.php");
}
}
?>
Now usually i would go through this line by line, BUT!

I'm not going too.

The observant amoung you will notice that this is dammed near exactly the same code as our edit guestbook posts page.

So there is no point me explaining it twice.

If you do requre an explanation of it.

Please click here.

Many thanks, and once again i hope you learned!

Cheers

Base

__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.

Last edited by Base; 04-05-2007 at 12:56 AM.
Reply With Quote
  #2 (permalink)  
Old 04-04-2007, 11:08 PM
Junior Member
 
Join Date: Mar 2007
Posts: 25
Willyke is on a distinguished road
Like all the other parts, good job and well-explained!

Just a little beauty mistakes (not really a mistake but you'll get my point )
Quote:
Originally Posted by Base View Post
PHP Code:
//the while loop
while($row=mysql_fetch_array($result))
{        
   
//getting each variable from the table
   
echo "".$row['name']."";
   echo 
"<br>";
   echo 
"".$row['message']."";
   echo 
"<br>";
   echo 
"<br>";

when you just echo the variables you don't need to use the "".$var."" and you can just use
PHP Code:
echo $var
Reply With Quote
  #3 (permalink)  
Old 04-05-2007, 12:55 AM
Base's Avatar
Senior Member
 
Join Date: Mar 2007
Location: North Yorkshire, UK
Posts: 121
Base is on a distinguished road
Send a message via MSN to Base Send a message via Skype™ to Base
rofl, realised that just before i read your reply..

lol was trying to get it done quickly as had other things to do :P

Edited now

Base
__________________
http://www.pointserv.co.uk/gfx/deal_..._pointserv.png
PointServ.co.uk - One of the UK's cheapest webhosting companies.

Last edited by Base; 04-05-2007 at 12:58 AM.
Reply With Quote
  #4 (permalink)  
Old 05-04-2007, 02:17 AM
Junior Member
 
Join Date: Dec 2006
Posts: 21
nose is on a distinguished road
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■
Reply With Quote
  #5 (permalink)  
Old 05-10-2007, 03:08 PM
Junior Member
 
Join Date: May 2007
Posts: 18
pazpoz is on a distinguished road
very good templte
Reply With Quote
  #6 (permalink)  
Old 05-11-2007, 07:15 AM
Junior Member
 
Join Date: May 2007
Posts: 13
Panaflakin is on a distinguished road
thanks for the tutorial
Reply With Quote
  #7 (permalink)  
Old 05-15-2007, 11:03 PM
Junior Member
 
Join Date: May 2007
Posts: 21
straitlaced is on a distinguished road
That is greate

That is greate
Reply With Quote
  #8 (permalink)  
Old 05-19-2007, 02:12 PM
Junior Member
 
Join Date: May 2007
Location: Croatia
Posts: 20
Jabba is on a distinguished road
Send a message via MSN to Jabba
thanks man!
Reply With Quote
  #9 (permalink)  
Old 08-02-2007, 09:53 PM
Junior Member
 
Join Date: Aug 2007
Posts: 3
slvcris is on a distinguished road
oooooo

valwe homenzinho estrangeiro

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +2. The time now is 11:47 PM.


Fake ID

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC8
Forums Copyright © Talk-Mania.com