Jump to content

etsted

Members
  • Posts

    274
  • Joined

  • Last visited

Everything posted by etsted

  1. etsted

    jquery

    still didnt work
  2. etsted

    jquery

    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
  3. 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();}
  4. <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
  5. 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>';
  6. So i have tried to ise jQuery with my AJAX, but i still have to refresh the page in order for the comment system to work. I am being able to post comments, but when i try to reply to that comment i get errors saying that serten variables are not set 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 function is used to reply a comment on an already existing thread
  7. i think that when i use AJAX to post a comment i somehow get a cached file from php.
  8. Can anyone tell me whats wrong?
  9. this is the button i am using $status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="'.$u.'"></textarea>'; $status_ui .= '<button id="statusBtn" onclick="postToStatus('status_post','a',''.$u.'','statustext',''.$DB_table.'')">Post</button>';
  10. so now i have tried to use jQuerys function $(document).ready function, it didnt work, i used the console.log, and saw that postToStatus was not defined... $(document).ready(function(){ $("#statusBtn").click(function(){function postToStatus(action,type,user,ta,document){ // store the value of the thread var data = _(ta).value; /*if(data === ""){ alert("Type something first"); return false; }*/ _("statusBtn").disabled = true; var ajax = ajaxObj("POST", "php_parsers/status_system2.php"); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) === true) { // split the incoming string, to get the last inserted id var datArray = ajax.responseText.split("|"); if(datArray[0] === "post_ok"){ // the inserted id var sid = datArray[1]; data = data.replace(/</g,"<").replace(/>/g,">").replace(/n/g,"<br />").replace(/r/g,"<br />"); // holds all the threads and replies var currentHTML = _("statusarea").innerHTML; _("statusarea").innerHTML = '<div id="status_'+sid+'" class="status_boxes"><div><b>Posted by you just now:</b> <span id="sdb_'+sid+'"><a href="#" onclick="return false;" onmousedown="deleteStatus(''+sid+'','status_'+sid+'');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span><br />'+data+'</div></div><textarea id="replytext_'+sid+'" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_'+sid+'" onclick="replyToStatus('+sid+','<?php echo $u; ?>','replytext_'+sid+'',this)">Reply</button>'+currentHTML; _("statusBtn").disabled = false; _(ta).value = ""; } else { alert(ajax.responseText); } } }; ajax.send("action="+action+"&type="+type+"&user="+user+"&data="+data+"&document="+document);} });});
  11. what do you mean? the View source code.
  12. well i was viewing the source code after posting a comment, and the source didnt macht with what was stored in the DB, then i refreshed the view source code, and suddently the code was machting the DB, any suggestions?
  13. well basically it contains replies for each thread that is being made.
  14. when a user clicks on the "remember me box" they should be rememered, but how would i indentify each computer used? Do i use $_SERVER['REMOTE_ADDR'], bcz i tried it, but i dont think that 127.0.0.1 is universal computer identificator.
  15. this is the content of the comments. <div id="status_75" class="status_boxes"> <div> <b>Posted by <a href="user.php?u=jacop">jacop</a> 2014-05-08 20:34:11:</b> <span id="sdb_75"><a href="#" onclick="return false;" onmousedown="deleteStatus('75','status_75','comments');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> &nbsp; &nbsp; <br />hei</div> </div> <textarea id="replytext_75" class="replytext" onkeyup="statusMax(this,250)" placeholder="write a comment here"></textarea><button id="replyBtn_75" onclick="replyToStatus(75,'george','replytext_75',this,'comments')">Reply</button>
  16. no, this is the button that i am pressing, but when i press it then the "alert(ajax.responseText)"; shows up with nothing, its empty
  17. <?php $sql = "SELECT * FROM $DB_table WHERE osid='$statusid' AND type='b' ORDER BY postdate ASC"; $query_replies = mysqli_query($con, $sql); $replynumrows = mysqli_num_rows($query_replies); if($replynumrows > 0){ while ($row2 = mysqli_fetch_array($query_replies, MYSQLI_ASSOC)) { $statusreplyid = $row2["id"]; $replyauthor = $row2["author"]; $replydata = $row2["data"]; $replydata = nl2br($replydata); $replypostdate = $row2["postdate"]; $replydata = str_replace("&","&",$replydata); $replydata = stripslashes($replydata); $replyDeleteButton = ''; // gives the author of the comment, or the page owner the ability to delete the reply if($replyauthor == $log_username || $account_name == $log_username ){ $replyDeleteButton = '<span id="srdb_'.$statusreplyid.'"><a href="#" onclick="return false;" onmousedown="deleteReply(''.$statusreplyid.'','reply_'.$statusreplyid.'',''.$DB_table.'');" title="DELETE THIS COMMENT">remove</a></span>'; } // holds all of the replies $status_replies .= '<div id="reply_'.$statusreplyid.'" class="reply_boxes"><div><b>Reply by <a href="user.php?u='.$replyauthor.'">'.$replyauthor.'</a> '.$replypostdate.':</b> '.$replyDeleteButton.'<br />'.$replydata.'</div></div>'; } }?>
  18. I used console.log(). Error: ReferenceError: replyid is not defined, but it is defined
  19. function loadXMLDoc(url, cfunc){ xmlhttp=new XMLHttpRequest(); xmlhttp.onreadystatechange=cfunc; xmlhttp.open("POST",url,true); xmlhttp.send("action=delete_reply&replyid="+replyid+"&document="+document);}function deleteReply(replyid,replybox,document){loadXMLDoc("php_parsers/status_system2.php",function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { _(replybox).style.display = 'none'; } else { alert(ajax.responseText); } });}
  20. etsted

    duplicate keys

    I tried to fix it by adding an increment to the $conversation_id like this: foreach($user_ids as $user_id) { $user_id = (int)$user_id; $values[] = "({$conversation_id}, {$user_id}, 0, '0')"; $conversation_id++; } But then it will only run 1 time, before displaying another duplicate key error
  21. etsted

    weird error

    <?php // THIS IS template_test.php, and i have included this both in watch.php and user.php$check_document = $_SERVER['PHP_SELF'];if($check_document == "/watch.php"){$DB_table = "comments";}else if($check_document == "/user.php"){$DB_table = "status";}// this is then button they will press to submit a threadif($check_document == "/watch.php") {if($user_status == true){$status_ui = '<textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="Hi '.$log_username.'"></textarea>';$status_ui .= '<button id="statusBtn" onclick="postToStatus('status_post','c',''.$u.'','statustext',''.$DB_table.'')">Post</button>';}}// so this button should contain "comments", bcz i am trying at watch.php, but i also tried it at user.php, and got the same error...// the comment i am trying to delete looks like this in "view source".<!-- holds the textarea to write in --><textarea id="statustext" onkeyup="statusMax(this,250)" placeholder="Hi jacop"></textarea><button id="statusBtn" onclick="postToStatus('status_post','c','george','statustext','comments')">Post</button></div>?><html><head>// this is how the ajax looks like:function deleteStatus(statusid,statusbox,document){var ajax = ajaxObj("POST", "php_parsers/status_system2.php");ajax.onreadystatechange = function() { if(ajaxReturn(ajax) == true) { if(ajax.responseText == "delete_ok"){ // remove the div all of the tekst is inside, the textarea and the reply button _(statusbox).style.display = 'none'; _("replytext_"+statusid).style.display = 'none'; _("replyBtn_"+statusid).style.display = 'none'; } else { alert(ajax.responseText); } }}ajax.send("action=delete_status&statusid="+statusid+"&document="+document);}</head></html><?php THIS IS php_parser/status_system2.phpif (isset($_POST['action']) && $_POST['action'] == "delete_status" && isset($_POST['document'])){if(!isset($_POST['statusid']) || $_POST['statusid'] == ""){echo "status id is missing";exit();}// sanitize the inserted status id$statusid = preg_replace('#[^0-9]#', '', $_POST['statusid']);// 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.phpif($_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";}else{ echo 'Error: this is an unexpected situation. What is happening? ' . $_POST['document'];} // Check to make sure the person deleting this reply is either the account owner or the person who wrote itif($DB_table == null){ echo 'Can't look up nuthin';}else{// Check to make sure the person deleting this reply is either the//account owner or the person who wrote it$sql = "SELECT account_name, author FROM $DB_table WHERE id='$statusid' LIMIT 1";$query = mysqli_query($con, $sql); while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $account_name = $row["account_name"]; $author = $row["author"]; }} // delete the thread and it replies with the same osid if ($author == $log_username || $account_name == $log_username) { $sql = "DELETE FROM $DB_table WHERE osid='$statusid'"; mysqli_query($con, $sql); echo "delete_ok"; exit(); }}?>
  22. etsted

    js validator

    i do have a semicolon on the line before it. It looks like this: } ajax.send("action="+action+"&type="+type+"&user="+user+"&data="+data+"&document="+document);};
  23. etsted

    weird error

    did i not provide u that? the button that is pressed, the ajax that recieves that call and the php if statement that handles it is up here
  24. etsted

    duplicate keys

    every time i run this code i get the error msg: Duplicate entry '2' for key 'user_id' <?php function create_conversation($user_ids, $subject, $body) { global $con; $subject = mysqli_real_escape_string($con, $subject); $body = mysqli_real_escape_string($con, $body); $sql = "INSERT INTO conversations VALUES('', '$subject')"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); $conversation_id = mysqli_insert_id($con); $sql = "INSERT INTO conversation_messages VALUES('', '$conversation_id', '{$_SESSION['user_id']}', NOW(), '$body')"; $query = mysqli_query($con, $sql) or die(mysqli_error($con)); $values = array(); $user_ids[] = $_SESSION['user_id']; //print_r($user_ids); foreach($user_ids as $user_id) { $user_id = (int)$user_id; $values[] = "({$conversation_id}, {$user_id}, 0, '0')"; } echo $sql = "INSERT INTO conversation_members VALUES " . implode(", ", $values); mysqli_query($con, $sql) or die(mysqli_error($con)); }?>
×
×
  • Create New...