Skip to content

Making a shoutbox with PHP, MySql and jQuery – Revisited

Recommendation to all my readers who have trouble with their hosting not installing PDO: change your hosting.

This is just an update on a previous tutorial which can be found here.

In that particular tutorial I am using PDO class to manipulate the MySql database. Everything else stays the same, except the code in shout.php file.

For all readers that can not use PDO, change the code in shout.php to this:

[code lang=”php”]
/*** mysql hostname ***/
$hostname = ‘localhost’;

/*** mysql username ***/
$username = ‘root’;

/*** mysql password ***/
$password = ”;

$dbname = ‘demo’;

mysql_connect($hostname, $username, $password);
mysql_select_db($dbname);

if($_POST[‘name’]) {
$name = mysql_real_escape_string($_POST[‘name’]);
$message = mysql_real_escape_string($_POST[‘message’]);

$sql = “INSERT INTO shoutbox (date_time, name, message)
VALUES (NOW(), ‘”.$name.”‘, ‘”.$message.”‘)”;

/*** run the sql statement ***/
if (mysql_query($sql)) {
populate_shoutbox();
}
}

if($_POST[‘refresh’]) {
populate_shoutbox();
}

function populate_shoutbox() {
$sql = “select * from shoutbox order by date_time desc limit 10”;
$rez = mysql_query($sql);
echo ‘

    ‘;
    while ($row = mysql_fetch_array($rez, MYSQL_ASSOC)) {
    echo ‘

  • ‘;
    echo ‘‘.date(“d.m.Y H:i”, strtotime($row[‘date_time’])).’‘;
    echo ‘‘.$row[‘name’].’‘;
    echo ‘‘.$row[‘message’].’‘;
    echo ‘
  • ‘;
    }
    echo ‘

‘;
}
[/code]

Now your shoutbox is working like a charm using mysql functions.


4 thoughts on “Making a shoutbox with PHP, MySql and jQuery – Revisited”

  1. Pingback: Making a shoutbox with PHP, MySql and jQuery – Revisited | Sharebrain

  2. Pingback: Making a shoutbox with PHP, MySql and jQuery – Revisited | Sharebrain

Comments are closed.