Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Posts posted by etsted

  1. And i got a file named inbox.page.inc.php that runs the function fetch_conversations_summary()

    <?php    $conversations = fetch_conversations_summary();?><div>    <a href="index2.php?page=new_conversation">new conversation</a>    <a href="index2.php?page=logout">Logout</a></div><div class="conversations"><?php    foreach ( $conversations as $conversation ){    ?>    <div class="conversation">        <h2><a href=""><?php echo $conversation['subject'];?></a></h2>        <p>Last reply: <?php echo $conversation['last_reply'];?></p>    </div><?php    }?></div>
  2. so i have changed the code for testing purpose only, instead of $_SESSION['user_id'] i just added 1 instead.

    this code is from the file private_message.inc.php<?php        // this will list all of the conversations to one user        function fetch_conversations_summary()        {            global $con;            $sql = "SELECT                     `conversations`.`conversation_id`,                    `conversations`.`conversation_subject`,                     MAX(`conversation_messages`.`message_date`) AS 'conversation_last_reply',                    MAX(`conversation_messages`.`message_date`) > 'conversation_last_reply'                    FROM `conversations`                    LEFT JOIN `conversation_messages` ON `conversations`.`conversation_id` = `conversation_messages`.`conversation_id`                    INNER JOIN `conversation_members` ON `conversations`.`conversation_id` = `conversation_members`.`conversation_id`                    WHERE `conversation_members`.`user_id` = 1                    AND `conversation_members`.`conversation_deleted` = '0'                    GROUP BY `conversations`.`conversation_id`                    ORDER BY `conversation_last_reply` DESC";                                $result = mysqli_query($con, $sql);                        $conversations = array();                        // store all of the id for each conversation, subject and last_reply date            while ( $row = mysqli_fetch_array($result) !== false )            {                $conversations[] = array(                    'id'        =>  $row['conversation_id'],                    'subject'   =>  $row['conversation_subject'],                    'last_reply'=>  $row['conversation_last_reply']                );            }                        return $conversations;        }?>

    Every time i run this i get this error:

    Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64 bytes) in C:wampwwwcoreincprivate_message.inc.php on line 24

     

    What does that mean?

  3. // check to see if the post variables are set, then validate them if it equals to true, then log them in    if(isset($_POST['user_name']) && isset($_POST['user_password']) )    {        if( ($user_id =validate_credentials($_POST['user_name'], $_POST['user_password'])) != false)        {            die(var_dump($user_id));            $_SESSION['user_id'] = $user_id['user_id'];                        header("location: index2.php?page=inbox");                        die();        }    }    

    i've tried to var_dump $user_id to se what it contains, and it contains 11 when it should contain 1, as thats what the user_id is in the DB

     

    here is how the function that returns the id from the DB looks like

    function validate_credentials($user_name, $user_password){    global $con;    $user_name = mysqli_real_escape_string($con, $user_name);    $user_password = mysqli_real_escape_string($con, $user_password);        $sql = "SELECT user_id FROM users WHERE user_name='$user_name' && user_password='$user_password' ";    $query = mysqli_query($con, $sql);    $results = mysqli_fetch_array($query);        if($results == 0)    {        return false;    }        return $results['user_id'];}

    Now in my DB i have i have a table called "users" with 3 columns. user_id which is autoincrement, user_name which has the username, and user_password. I dont have a register form, i just make the user in phpmyadmin for testing purpose.

  4. conversations table:

    conversation_id.

    conversation_subject.

    conversations is a table that creates an id foreach conversation and stores the subject of each conversation.

     

    conversation_members table:

    id.

    conversation_id.

    user_id.

    conversations_last_view

    conversation_deleted.

     

    the conversation_id corresponds to the conversation_id inside the conversations table. user_id is the id of each user. conversations_last_view is the date of when someone last viewed the conversation. conversation_deleted tells wheter a user has deleted the conversation.

     

     

    conversation_messages table:

    message_id.

    conversation_id.

    user_id.

    message_date.

    message_text.

     

    message_id i autoincrement. the conversation_id corresponds to the conversation_id inside the conversations table. user_id is the id of each user. message_date tellst when the last message was implemented. message_text holds the message.

  5. I have fixed the error, but now face antoher one.

    SELECT                     `conversations`.`conversation_id`,                    `conversations`.`conversation_subject`,                     MAX(`conversation_messages`.`message_date`) AS 'conversation_last_reply',                    MAX(`conversation_messages`.`message_date`) > 'conversation_last_reply'                    FROM `conversations`                    LEFT JOIN `conversation_messages` ON `conversations`.`conversation_id` = `conversation_messages`.`conversation_id`                    INNER JOIN `conversation_members` ON `conversations`.`conversation_id` = `conversation_members`.`conversation_id`                    WHERE `conversation_members`.`user_id` = {$_SESSION['user_id']}                    AND `conversation_members`.`conversation_deleted` = '0'                    GROUP BY `conversation`.`conversation_id`                    ORDER BY `conversation_last_reply` DESC

    this keeps giving me an error: Unknown column 'Array' in 'where clause'

    What this SQL statement is supposed to do is select all of a users messages from the database.

    Ive tried to print_r $_SESSION['user_id'] and got this: Array ( [0] => 1 [user_id] => 1 )

     

    im not sure why the [0] => 1 is there, but this is how i make the session.

    if( ($user_id = validate_credentials($_POST['user_name'], $_POST['user_password'])) != false)        {            $_SESSION['user_id'] = $user_id;                        header("location: index2.php?page=inbox");                        die();        }

    this is supposed to check if the user exist, if so then create a session.

     

    this i the content of validate_credentials

    function validate_credentials($user_name, $user_password){    global $con;    $user_name = mysqli_real_escape_string($con, $user_name);    $user_password = mysqli_real_escape_string($con, $user_password);        $sql = "SELECT user_id FROM users WHERE user_name='$user_name' && user_password='$user_password' ";    $query = mysqli_query($con, $sql);    $results = mysqli_fetch_array($query);        if($results == 0)    {        return false;    }        return $results;}
  6. keep getting this error: 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 '.'conversation_id', 'conversations'.'conversation_subject' ' at line 2

    $sql = "SELECT                     'conversations'.'conversation_id',                    'conversations'.'conversation_subject'                    MAX('conversation_messages'.'message_date') AS 'conversation_last_reply'                    FROM 'conversations'                    LEFT JOIN 'conversation_messages' ON 'conversations'.'conversation_id' = 'conversation_messages'.'conversation_id'                    INNER JOIN 'conversation_members' ON 'conversations'.'conversation_id' = 'conversation_members'.'conversation_id'                    WHERE 'conversation_members'.'user_id' = {$_SESSION['user_id']}                    AND 'conversation_members'.'conversation_deleted' = '0'                    GROUP BY 'conversation'.'conversation_id'                    ORDER BY 'conversation_last_reply' DESC";
  7.  

    Another problem is that the function heidi() isn't global, it's not accessible from the element's onclick scope. Put the function declaration outside of the .ready() handler.

     

    The hilsen="heidi" syntax doesn't work in Javascript, that's a C++ / Java / PHP thing. If you want to give a default value then you'll have to set it inside the function:

    function heidi(hilsen) {    if(typeof hilsen == "undefined") {        hilsen = "heidi";    }

    But if i would to call that function, would it still wait for the page to load, before running whats inside the jquery function, since the jquery ready function is set?

  8. I think i have been using jquery wrong, or maybe not the best way. I want to wrap jquery outside javascript functions, to make sure that the page i fully loaded, so that i wont have any cached files, when i make a request with ajax.

    <!DOCTYPE html><html><head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script><script>$(document).ready(function(){  $("#statusBtn").click(function(){    function heidi(hilsen="heidi"){     return hilsen;    }document.write(heidi());  });});</script></head><body><button id="statusBtn" onclick="heidi('lars')">klikk</button></body></html>

    Now i have tried this an it works, except not the way i want, the parameter "lars" is not being set, and this returns "heidi" instead

  9. At top i have a variable that checks to see which of the page the user is on

    $check_document = $_SERVER['PHP_SELF'];    if($check_document == "/watch.php")    {        $DB_table = "comments";    }    else if($check_document == "/user.php")    {        $DB_table = "status";    }

    this is the reply textarea

    $statuslist .= '<textarea id="replytext_'.$statusid.'" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_'.$statusid.'" onclick="replyToStatus('.$statusid.',''.$u.'','replytext_'.$statusid.'',this,''.$DB_table.'')">Reply</button>';	    

    this is the javascript that is supposed to handle the input the user just typped in, then send it of to php_parsers/status_system2.php

    function replyToStatus(sid,user,ta,btn,document) {    $(document).ready(function(){        // sid holds the id that associate each thread with all of its replies         // get the values inside the textarea    var data = _(ta).value;        if(data === ""){        alert("Type something first");        return false;    }            // select the buttons id    _("replyBtn_"+sid).disabled = true;            $.post("php_parsers/status_system2.php","action=status_reply&sid="+sid+"&user="+user+"&data="+data+"&document="+document,function(information){            // split the incoming string, to get the last inserted id            var datArray = information.split("|");                            if(datArray[0] === "reply_ok"){                // contains the last inserted id to the DB                var rid = datArray[1];                                // sanitize the data, the user wrote in                data = data.replace(/</g,"<").replace(/>/g,">").replace(/n/g,"<br />").replace(/r/g,"<br />");                                // contains the reply                _("status_"+sid).innerHTML += '<div id="reply_'+rid+'" class="reply_boxes"><div><b>Reply by you just now:</b><span id="srdb_'+rid+'"><a href="#" onclick="return false;" onmousedown="deleteReply(''+rid+'','reply_'+rid+'');" title="DELETE THIS COMMENT">remove</a></span><br />'+data+'</div></div>';                _("replyBtn_"+sid).disabled = false;                                // empty the textarea                _(ta).value = "";            } else {                alert(information);            }                        });    });};

    this is the ajax that will hande the AJAX call

    //action=status_reply&sid="+sid+"&user="+user+"&data="+dataif (isset($_POST['action']) && $_POST['action'] == "status_reply" && !empty($_POST['document']) ){        // Make sure data is not empty    if(strlen($_POST['data']) < 1){       echo "data_empty";       exit();    }        // Clean the posted variables    $osid = preg_replace('#[^0-9]#', '', $_POST['sid']);    $account_name = preg_replace('#[^a-z0-9]#i', '', $_POST['user']);    $data = htmlentities($_POST['data']);    $data = mysqli_real_escape_string($con, $data);        // Make sure account name exists (the profile being posted on)    $sql = "SELECT COUNT(id) FROM register WHERE u_name='$account_name' AND activated='1' LIMIT 1";    $query = mysqli_query($con, $sql);    $row = mysqli_fetch_row($query);        if($row[0] < 1){        echo "the user doesnt exist";        exit();    }        // check to see which page the user is on, then give different variables that contain different DB tables// check to see whether or not the user replied to a status from user.php or watch.php    if($_POST['document'] == "comments") // this means the user replied within watch.php    {        $DB_table = "comments";    }    else if($_POST['document'] == "status") // this mean that the user replied within user.php    {        $DB_table = "status";    }        // Insert the status reply post into the database    $sql = "INSERT INTO $DB_table(osid, account_name, author, type, data, postdate)           VALUES('$osid','$account_name','$log_username','b','$data',now())";    $query = mysqli_query($con, $sql);        // get the inserted id    // to allows the writer or the account owner to delete the reply    $id = mysqli_insert_id($con);        // Insert notifications for everybody in the conversation except this author    $sql = "SELECT author FROM $DB_table WHERE osid='$osid' AND author!='$log_username' GROUP BY author";    $query = mysqli_query($con, $sql);        while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {        $participant = $row["author"];        $app = "Status Reply";        $note = $log_username.' commented here:<br /><a href="user.php?u='.$account_name.'#status_'.$osid.'">Click here to view the conversation</a>';        mysqli_query($con, "INSERT INTO notifications(username, initiator, app, note, date_time)                     VALUES('$participant','$log_username','$app','$note',now())");    }    echo "reply_ok|$id";    exit();}
  10. <textarea id="replytext_8" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_8" onclick="replyToStatus(8,'george','replytext_8',this,'comments')">Reply</button>

    If you need to know, the content of the reply textarea looks like this, but i think i have a cache problem

  11. They get set when a user fills up a textarea, and hits a button.

    $statuslist .= '<textarea id="replytext_'.$statusid.'" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_'.$statusid.'" onclick="replyToStatus('.$statusid.',''.$u.'','replytext_'.$statusid.'',this,''.$DB_table.'')">Reply</button>';
×
×
  • Create New...