Another new PHP programmer question...

Another new PHP programmer question...

am 03.01.2008 09:56:58 von Ben Stones

------=_Part_15562_30717312.1199350618264
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hello,

Thank you for your help previously everyone, I was able to fix that problem.
The thing now, is that I want to add smileys to the messages; i.e. :) would
equal to a smiley image when posting a message.

$con = mysql_connect("localhost","removed","removed") or die("con");
$db = mysql_select_db("ben_test") or die("db");

$post = $_POST['comment'];

if(empty($post)){
echo "Post rejected, field left empty />";
}
else if(is_numeric($post)){
echo "Post rejected, numeric data submitted />";
}
else if(preg_match("/www/", $post)) {
echo "Post rejected. Advertising is prohibited! />";
}

else {
mysql_query("INSERT INTO `comments`(`messages`) VALUES ('$post')") or
die(mysql_error());
}

$mysql_query_one = mysql_query("SELECT * FROM `comments`");
while($rows=mysql_fetch_array($mysql_query_one)) {
echo $rows['messages'] . "


";

I have grasped quite a lot so far, and added many complementry features,
however this is only my first script - so hence it is pretty much basic as
it is!

Thanks once again, hoping someone can assist me further.

------=_Part_15562_30717312.1199350618264--

Re: Another new PHP programmer question...

am 04.01.2008 00:22:47 von dmagick

Ben Stones wrote:
> Hello,
>
> Thank you for your help previously everyone, I was able to fix that problem.
> The thing now, is that I want to add smileys to the messages; i.e. :) would
> equal to a smiley image when posting a message.

Assuming you have images/smiley.gif on your server, it's pretty simple:

echo '';

at the right place.

> else {
> mysql_query("INSERT INTO `comments`(`messages`) VALUES ('$post')") or
> die(mysql_error());
> }

You're still not escaping your data and you will run into problems
unless you start doing it.

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Another new PHP programmer question...

am 04.01.2008 17:12:17 von parasane

On Jan 3, 2008 3:56 AM, Ben Stones wrote:
> Hello,
>
> Thank you for your help previously everyone, I was able to fix that problem.
> The thing now, is that I want to add smileys to the messages; i.e. :) would
> equal to a smiley image when posting a message.

Where you want that, add this:

$smile = array(':-)' => 'smile',
':)' => 'smile',
';-)' => 'wink',
';)' => 'wink',
':-P' => 'tongue',
':P' => 'tongue');

foreach($smile as $p => $v) {
// The following is done to allow the regexp to function normally.
$p = str_replace(')','\)',str_replace('(','\(',$p));
$post = preg_replace('/'.$p.'/U',' src="/graphics/smileys/'.$v.'.gif" />',$post);
}
?>

This assumes that you have smiley images in /graphics/smileys/ and
that they're .gif images named as shown in the second part of each
array item.

Also, keep in mind that, before you insert ANY user-posted data
into your database, you should escape it. For example:

$post = mysql_real_escape_string($post);

--
Daniel P. Brown
[Phone Numbers Go Here!]
[They're Hidden From View!]

If at first you don't succeed, stick to what you know best so that you
can make enough money to pay someone else to do it for you.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php