Source: http://www.media-ops.com
My first ever tutorial! (php wise...). I first made this for www.re-mi.be, which is currently down, and then updated it and now i use it on my personal site www.r.dsx3.com :P. Its a basic script, but if you would like a shout box then it is perfect :P.
There will be 5 parts to this tutorial:
>Making the SQL Table
>Creating the Form
>Creating the Action
>Creating the Output
>Creating the index
lets get started :P.
Open up Phpmyadmin, or whatever you use for sql. Run this query
You can change the 100 (in the paranthesis) to however many characters you would like to limit the peoples messages to.Code:CREATE TABLE `shout` ( `id` INT NOT NULL AUTO_INCREMENT , `name` TEXT NOT NULL , `message` TEXT( 100 ) NOT NULL , PRIMARY KEY ( `id` ) );
What the query does, for people who dont get it: It creates a table called shout, and makes three rows. ID, name, and message. The name and message are inputted by the user, and the id automaticaly increases each time a person "shouts".
now create a directory called shout. You dont want things to get all ugly and disorganized :P.
Now we are going to create the form. Name this add.php
I put it in the table so i could control the alignment :P. You could/should add some css, to make the inputs look pretty :P, because the default ones arent so.Code:<form name="addform" method="post" action="shoutbox/action.php"> <table width="150" border="0" cellspacing="0" cellpadding="0"> <tr> <td><b>Name:</b></td> <td><input type="text" id="name" name="name"></td> </tr> <tr> <td><b>Msg:</b></td> <td><input type="text" id="message" name="message"></td> </tr> </table> <table width="150" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><input type="submit" name="shout" title="shout" value="shout"></td> </tr> </table> </form>
Now we are going to make the action file. Name this action.php <-- :P
Make sure, when you change the href, to keep the last \ there :P. Change the username pswrd and databae names also.Code:<?php //fill it out according to the sql table you set up $username="Username"; $password="Password"; $database="Database"; $table="shout"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="INSERT INTO $table (id, name, message) values ('$id','$name','$message')"; $result=mysql_query($query); echo "Succsesfully Shouted. <a href=\"http://www.yoursite.com\">Return</a>"; ?>


LinkBack URL
About LinkBacks






Reply With Quote