Jump to content

How to Make Smilies Work


RTS

Recommended Posts

not quite sure how to put that in my code, but atleast I tried. it gave me [code]Parse error: parse error in /Library/WebServer/Documents/read.php on line 7[/code]

Heres my script
read.php
[quote]<?php
$con = mysql_connect("localhost","ZackBabtkis","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM messages WHERE ID=".$_GET['id']);
while($row = mysql_fetch_array($result))
  {
$the_text = echo "<table border=10 width=400 cellpadding=0 cellspacing=3><tr><td background=table.jpg><h1 align=center>Message:</h1>" . $row['Message'];
$smilies = array( // code => image
':)' => '<img src=smilies/smile.gif>',
);

$codes = array_keys($smilies);

$the_text = str_replace($codes,$smilies,$the_text);

  }
echo "</td></tr></table>";

mysql_close($con);
?>[/quote]
You had a few badf syntax errors. Using echo within  variable is not allowed and thus why you got the parse error. I have corrected this issue and tidy'd up your code a little too:
[code]<?php

$con = mysql_connect("localhost","ZackBabtkis","") or die('Could not connect: ' . mysql_error());
mysql_select_db("test", $con);

$result = mysql_query("SELECT * FROM messages WHERE ID=" . $_GET['id']);

while($row = mysql_fetch_array($result))
{
    $the_text = '<table border="10" width="400" cellpadding="0" cellspacing="3">
    <tr>
        <td background="table.jpg">
            <h1 align="center">Message:</h1>' . $row['Message'];

    $smilies = array( // code => image
        'Smiley' => '<img src=smilies/smile.gif>',
    );

    $codes = array_keys($smilies);

    $the_text = str_replace($codes,$smilies,$the_text);

    echo $the_text;
}

echo "      </td>
    </tr>
</table>";

mysql_close($con);

?>[/code]
hmmmm, that didnt give me an error, but just showd up as the text ": )" do I need to have it in the message being sent? how would I put it in this code?
send.php:
[code]<?php
session_start();
$con = mysql_connect("localhost","ZackBabtkis","");
$subject = mysql_real_escape_string($_POST[subject]);
$message = mysql_real_escape_string($_POST[message]);
$user = $_COOKIE["user"];
$sender = $_SESSION['username'];
$date = date("F j, Y, g:i a");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("test", $con);
$sql = "INSERT INTO messages (Username, Sender, Subject, Message, Date) VALUES ('$user','$sender','$subject','$message', '$date')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "Your message has been sent to $user";
mysql_close($con)
?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.