Shout Box

Written by @m_k_amin 27 December 2012

This is a nice shout box for your site. You can also edit your shout. It is just one page script and has database setup in it and just needs username and password of the database server.

Code Snippet:

                                                
                                                <!-- this script is provided by www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
	$host="localhost"; // Host name
	$username="root"; // Mysql username
	$password=""; // Mysql password

function setup(){
echo('
<p style="color: #008000;	text-align: left;	font-size: 15pt;"">-Automatic setup is started...</p>
');
global $host,$username,$password,$link;
//$link=mysql_connect($host, $username, $password);
$sql= 'CREATE DATABASE shout';
if (!mysql_query ($sql, $link)) die('
<p style="text-align: center;	font-size: 20pt;"><span style="color: #FF0000;">Failed to 
create database! </span><br><span style="font-size: 12pt;">&gt;&gt;Please check the parameters and database server&lt;&lt;</span></p>
');
$sql = "CREATE TABLE `shout`.`myshout` (
`ID` INT NOT NULL ,
`who` TEXT NOT NULL,
`txt` TEXT NOT NULL
) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci;";

mysql_query($sql) or die('Setup Failed');
echo('
<p style="color: #008000;	text-align: left;	font-size: 15pt;"">-Automatic setup completed successfully. Your Database is ready!</p>
');
}

$link=mysql_connect($host, $username, $password);
if(!$link) die('
<p style="text-align: center;	font-size: 20pt;"><span style="color: #FF0000;">Failed to connect to the database! </span>
<br><span style="font-size: 12pt;">&gt;&gt;Please check the parameters and database server&lt;&lt;</span></p>
');
$db_name="shout"; 
$result=mysql_select_db($db_name);
if(!$result){
	setup();
}
if (isset($_POST['shout'])){
	$txt=$_POST['txt'];
	if ($_GET['mode']=='create')
		$sql="INSERT INTO myshout(ID,who,txt)VALUES(0,'me', '$txt')";
	else
		$sql="UPDATE myshout SET txt='$txt' WHERE ID=0";
	$result=mysql_query($sql);
	if (!$result) die (mysql_error());

}
$mode='?mode=edit';
$sql="SELECT * FROM myshout WHERE ID=0";
$result=mysql_query($sql);
@$rows=mysql_fetch_array($result);
if (!$rows){
	$edit=true;
	$mode='?mode=create';	
}else
	$edit=false;

if (isset($_POST['edit'])) $edit=true;

?>
<body OnLoad="document.myform.txt.focus()">
<form name="myform" method="post" action="<?php echo $_SERVER['PHP_SELF'].$mode; ?>">
<table align="center" style="border: 2px solid #008080; width: 600px; background-color: #FFFFDD;" cellpadding="5">
	<tr>
		<td style="font-family: 'Times New Roman', Times, serif; width: 54px; font-size: 20pt; color: #0D7B09;">
		<strong>Me:</strong></td>
		<td style="width: 422;font-family: 'Times New Roman', Times, serif;font-size: 20pt; color: #700303;">
<?php if ($edit==true){ ?>
			<input name="txt" style="font-family: 'Times New Roman', Times, serif; font-size: 20pt; width: 422px" value="<?php if (isset($_POST['edit']))echo $rows['txt'] ?>">
		</td>
		<td style="text-align: center">
			<input name="shout" style="font-family: 'Times New Roman', Times, serif; font-size: 16pt; color: #0D7B09; width: 77px; height: 42px;" type="submit" value="Shout">
<?php }else{ 	
		echo $rows['txt']?></td>
		<td style="text-align: center; width: 48px;">		
			<input name="edit" style="font-family: 'Times New Roman', Times, serif; font-size: 14pt; color: #7B0909" type="submit" value="Edit">
<?php } ?>
	</td></tr>
</table>
</form>
<?php if (isset($_POST['edit'])){ ?>
<script>
el=document.myform.txt
    if (typeof el.selectionStart == "number") {
        el.selectionStart = el.selectionEnd = el.value.length;
    } else if (typeof el.createTextRange != "undefined") {
        el.focus();
        var range = el.createTextRange();
        range.collapse(false);
        range.select();
    }</script>
<?php } ?>
<div style="text-align: center">
<font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/">
<span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font>
</div>

</body><a target='_blank' href='www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: grkkid, Manaakividuinfo.com, karticksv, sava, tinatina
advertisement 2