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 . Its a basic script, but if you would like a shout box then it is perfect .
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 .
Open up Phpmyadmin, or whatever you use for sql. Run this query
Code:
You can change the 100 (in the paranthesis) to however many characters you would like to limit the peoples messages to.
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 .
Now we are going to create the form. Name this add.php
Code:
I put it in the table so i could control the alignment . You could/should add some css, to make the inputs look pretty , because the default ones arent so.
Now we are going to make the action file. Name this action.php <--
Code:
Make sure, when you change the href, to keep the last \ there . Change the username pswrd and databae names also.
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 . Its a basic script, but if you would like a shout box then it is perfect .
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 .
Open up Phpmyadmin, or whatever you use for sql. Run this query
Code:
CREATE TABLE `shout` (
`id` INT NOT NULL AUTO_INCREMENT ,
`name` TEXT NOT NULL ,
`message` TEXT( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
);
`id` INT NOT NULL AUTO_INCREMENT ,
`name` TEXT NOT NULL ,
`message` TEXT( 100 ) NOT NULL ,
PRIMARY KEY ( `id` )
);
You can change the 100 (in the paranthesis) to however many characters you would like to limit the peoples messages to.
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 .
Now we are going to create the form. Name this add.php
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>
<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>
I put it in the table so i could control the alignment . You could/should add some css, to make the inputs look pretty , because the default ones arent so.
Now we are going to make the action file. Name this action.php <--
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>";
?>
//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>";
?>
Make sure, when you change the href, to keep the last \ there . Change the username pswrd and databae names also.