Page 1 of 1

smilies guestbook

Posted: Sun Feb 20, 2005 1:00 pm
by kanchan
i have made this

Code: Select all

<html><title>test</title>
<script type="text/javascript">
<!--
function addsmiley(code)
{
var pretext = document.news.message.value;
this.code = code;
         document.news.message.value = pretext + code;
}
//-->
</script>
<body>

<form name=news method=post action=add.php>
  <table width="28%" border="0" cellspacing="0" cellpadding="0">
    <tr> 
      <td width="28%">Name :</td>
      <td width="72%"><input name="name" type="text" id="name"></td>
    </tr>
    <tr> 
      <td> </td>
      <td>
	  	<img src="angry_smile.gif" alt="Angry" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':@')">
		<img src="confused_smile.gif" alt="Confused" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':s')">
		<img src="cry_smile.gif" alt="Crying" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':'(')">
		<img src="dissapointed_smile.gif" alt="Dissapointed" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':|')">
		<img src="embrassed_smile.gif" alt="Embrassed" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':$')">
		<img src="heart.gif" alt="Heart" width="19" height="19" style="cursor: pointer;" onClick="addsmiley('l')"> 
        <img src="open_mouth_smile.gif" alt="Open Mouth Smile" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(':d')"> 
        <br>
        <img src="present.gif" alt="Gift" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley('g')">
		<img src="rose.gif" alt="Red Rose" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley('f')"> 
        <img src="sad_smile.gif" alt="Sad" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(':(')">
		<img src="smile.gif" alt="Smile" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(':)')"> 
        <img src="surprise.gif" alt="Surprise" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(':o')">
		<img src="tongue_out_smile.gif" alt="Tongue Out" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(':p')"> 
        <img src="wink_smile.gif" alt="Wink" width="19" height="19"  style="cursor: pointer;" onClick="addsmiley(';)')">
		</td>
    </tr>
    <tr> 
      <td>Message :</td>
      <td><textarea name="message" rows="5" id="message"></textarea></td>
    </tr>
    <tr> 
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>

</html>
add.php

Code: Select all

<?php
$user="root";
$pwd="password";
$db="db";
$host="localhost";
$conn=mysql_connect("$host","$user","$pwd")
	or die("Couldn't connect to MYSQL.");

$name=$_POSTї'name'];
$message=$_POSTї'message'];
mysql_select_db($db);
if (!$conn){print "error: " . mysql_error() . "\n";}

$sql = "INSERT INTO msg (name,message) VALUES ('$name', '$message')";
$result = mysql_query($sql, $conn);
if (mysql_error()) { print "Database ERROR: $sql " . mysql_error(); }

?>
mY problem is that how to show the smiles....

i don't know the code.... can anybody help me...????



feyd | use

Code: Select all

tags while

Code: Select all

tags are down![/color]

Posted: Sun Feb 20, 2005 1:12 pm
by feyd
first off you have invalid Javascript in your code:

Code: Select all

<img src="cry_smile.gif" alt="Crying" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':'(')">
the second apostrophe needs to be escaped.

'this.code = code' isn't needed.

I don't quite understand your question though. It looks like the basics of it should work.

Posted: Sun Feb 20, 2005 1:26 pm
by smpdawg
I just tried it with feyd change and it works as expected. A textarea is for displaying text not images. In fact if you try the smiilies in this forum it will do the same thing that yours does. So you are basically at the end of the road because it is doing all that it should be doing.

If you were want to show the smilies you would need to have a little preview area. Perhaps a div or span that you would modify using .innerHTML and send it the text and the img tags.

Posted: Mon Feb 21, 2005 10:26 am
by kanchan
feyd wrote:first off you have invalid Javascript in your code:

Code: Select all

<img src="cry_smile.gif" alt="Crying" width="19" height="19" style="cursor: pointer;" onClick="addsmiley(':'(')">
the second apostrophe needs to be escaped.

'this.code = code' isn't needed.

I don't quite understand your question though. It looks like the basics of it should work.


then can u please give ur code...

i just need it.....

Posted: Mon Feb 21, 2005 10:28 am
by feyd
adjust the two things I listed... there's no code I had.


Don't forget to read your private messages. :|