PHP private message tuturial

Post here is you are having problems with any of the tutorials.
Post Reply
manuor
Posts: 3
Joined: Tue Jun 04, 2013 9:53 am

PHP private message tuturial

Post by manuor »

Hello I am having a problem with part 7 of this tutorial, it is pretty simple but I cant figure out where the error might be.
The error s basically telling me that my $user_names is not a array, I have checked all the spelling and watch the video 3 times, if anyone could help be I would sincirely appreciated.
here is my code
if(isset($_POST['to'], $_POST['subject'], $_POST['body'])){
    $errors = array();
    if(empty($_POST['to'])){
        $errors[]= 'Necesitas añadir un destinatario';
    }else if(preg_match('#^[a-z, ]+$#', $_POST['to']) === 0){
        $errors[]= 'La lista de nombres que has introducido no es correcta.';
    }else{
        $user_names= explode(',', $_POST['to']);
        
        foreach($user_names as &$name){
            $name= trim($name);
        }
        $user_ids = fetch_user_ids($user_names);
        
        if(count($user_ids)!== count($user_names)){
            $errors[]= 'Los siguientes usuarios no han sido encontrados: '. implode(', ', array_diff($user_names, array_keys($user_ids)));
        }
    }
Thank you
manuor
Posts: 3
Joined: Tue Jun 04, 2013 9:53 am

Re: PHP private message tuturial

Post by manuor »

Hello another problem I am getting that I don't know how to solve is that in part 9 my query is falling giving me this message,

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND `conversations_members`.`conversation_deleted` = 0 GROUP BY' at line 9

I think my code is exactly as the one in the tutorial, and I have checked with manuals and other online resources and I can't find where the sintaxis problem is, if any one could help me I would be thankfull.

Thank you very much
manuor
Posts: 3
Joined: Tue Jun 04, 2013 9:53 am

Re: PHP private message tuturial

Post by manuor »

here is my code by the way:
   $sql = "SELECT
                `conversations`.`conversation_id`,
                `conversations`.`conversation_subject`,
                MAX(`conversations_messages`.`message_date`) AS `conversation_last_reply`
                FROM `conversations`
                LEFT JOIN `conversations_messages` ON `conversations`.`conversation_id` = `conversations_messages`.`conversation_id`
                INNER JOIN `conversations_members` ON `conversations`.`conversation_id` = `conversations_members`.`conversation_id`
                WHERE `conversations_members`.`user_id` = {$_SESSION['user_id']}
                AND `conversations_members`.`conversation_deleted` = 0
                GROUP BY `conversations`.`conversation_id`
                ORDER BY `conversation_last_reply` DESC";
 
     $result = mysql_query($sql);
jlndk
Posts: 2
Joined: Fri Jun 28, 2013 6:26 pm

Re: PHP private message tuturial

Post by jlndk »

if you have problems with your mysql query. try to paste your query into phpmyadmin and replace variables with a number eg. {$_SESSION['user_id']} should be replaced with a number like 1. it is sometime easyer to check querys from phpmyadmin
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: PHP private message tuturial

Post by Helx »

If you believe that you've correctly followed the tutorial, then it may be an issue with actually connecting to the MySQL database.
Please have a look-through and check some of the things here: http://betterphp.co.uk/board/viewtopic.php?f=7&t=2223

If any errors are displayed, please post them in this thread.
Post Reply