Tuesday, March 11, 2014

Status Update System By PHP Source Code

Hi, PHP lovers!

There is no such people who has come here and didn't yet have  a Facebook account. In Facebook, we used to give status. It's like saying something to the friends. Well, certainly, the PHP beginners will love to test something like that status update. It's not a tough job.
We will do a simple status update action. For this you need a database to keep data. I'll show and talk about MySQL database structure and connection with PHP later, now just see the codes. The below image is of PHP status update panel:






And the PHP codes works behind it is below codes:


<?php
if(isset($_POST['status'])){

include('./db.php');
$user = $_SESSION['username'];
$sta = htmlentities(mysql_real_escape_string($_POST['status']));
$dat = date("h-i-s-A/d-m-Y");

$qu = mysql_query("insert into tab3 values(id,'$user','$sta','$dat')");
 
if(!$qu) die("Error ".mysql_error());
else {
header('Location: ./status.php');
}
}

?>

<?php
include('./db.php');
$qu2 = mysql_query("select * from tab3");

$i=0;
while($row = mysql_fetch_array($qu2))
{
$un[] = $row['username'];
$st[] = $row['status'];
$dt[] = $row['date'];
$i++;
}
$revun = array_reverse($un);
$revst = array_reverse($st);
$revdt = array_reverse($dt);
for( $p=0; $p < sizeof($revun); $p++ ){
echo "<tr><td class='lefttd2'><h5 class='h6cl'>".ucfirst($revun[$p])."</h5><br></td>
<td class='righttd2'><small>".$revdt[$p]."</small><h6 class='h6cl'> ".$revst[$p]."</h6></td></tr>";

}
?>


Hope the codes works for you! :)
Cheers, see you in next article.

Read More: Email Contact PHP Codes

1 comment: