Page 1 of 1

mysql error, i need help pls

Posted: Fri May 22, 2009 5:28 am
by jade756
hello everyone..
well, im making a simple chatroom..

Code: Select all

<?php
    require '../db/db_connect.php';
    require '../db/session.php';
    $id=$_SESSION['id'];
    $message=$_POST['message'];
    if($message==null)
        header("Location: ../messagearea.php");
    
    else
        {
          $time = date('Y').date('m').date('d').date('h').date('i').date('s');
          $insert1 = "INSERT INTO mainchat
                    (mainID, chatID, maintime, message) VALUES
                    ('', '$id', '$time', '$message')";
                    
        if(!mysql_query($insert1))
        { die(mysql_error()); }
    
        else
        { header("Location: ../messagearea.php"); }
?>
 
here my problem:
if $message contains a " ' " (ex. I'm here).. this generate an error in the insert statement..
when $message doesnt contain " ' ", its works fine..

btw, the $message is a LONGTEXT.. does it matter.. but I changed it to MEDIUMTEXT and TEXT but it still have that error when $message contains " ' "
thanks in advance

Re: mysql error, i need help pls

Posted: Fri May 22, 2009 5:41 am
by susrisha
google out for mysql_real_escape_string function

Code: Select all

 
mysql_real_escape_string();
 

Re: mysql error, i need help pls

Posted: Fri May 22, 2009 1:44 pm
by anand
susrisha wrote:google out for mysql_real_escape_string function

Code: Select all

 
mysql_real_escape_string();
 
+1.

You should try this

Code: Select all

mysql_real_escape_string($message);

This will escape all \n , \r , ' and so on.

Re: mysql error, i need help pls

Posted: Sat May 23, 2009 9:13 pm
by jade756
thank u very much for your reply.. :mrgreen: