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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.