Another new PHP programmer question...

------=_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 "<font color='red'><b>Post rejected, field left empty<br
/></b></font>";
}
else if(is_numeric($post)){
echo "<font color='red'><b>Post rejected, numeric data submitted<br
/></b></font>";
}
else if(preg_match("/www/", $post)) {
echo "<font color='red'><b>Post rejected. Advertising is prohibited!<br
/></b></font>";
}

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'] . "<hr>";

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--
Ben Stones [ Do, 03 Januar 2008 09:56 ] [ ID #1899129 ]

Re: Another new PHP programmer question...

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 '<img src="images/smiley.gif">';

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
dmagick [ Fr, 04 Januar 2008 00:22 ] [ ID #1899134 ]

Re: Another new PHP programmer question...

On Jan 3, 2008 3:56 AM, Ben Stones <bastones [at] googlemail.com> 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','<img
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
parasane [ Fr, 04 Januar 2008 17:12 ] [ ID #1900008 ]
PHP » gmane.comp.php.database » Another new PHP programmer question...

Vorheriges Thema: undefined function Mysql_connect()
Nächstes Thema: Sample script files with 3 different select boxes with mysql conditions in select boxes