etsted
-
Posts
274 -
Joined
-
Last visited
Content Type
Profiles
Forums
Events
Posts posted by etsted
-
-
i think that when i use AJAX to post a comment i somehow get a cached file from php.
-
Can anyone tell me whats wrong?
-
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>';
-
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);} });});
-
Viewing source code how?
what do you mean? the View source code.
-
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?
-
well basically it contains replies for each thread that is being made.
-
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.
-
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>
<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>
-
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
-
<?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>'; } }?>
-
I used console.log(). Error: ReferenceError: replyid is not defined, but it is defined
-
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); } });}
-
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
-
<?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(); }}?>
-
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);};
-
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
-
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)); }?>
-
and this: ajax.send("action="+action+"&type="+type+"&user="+user+"&data="+data+"&document="+document); ====^ lint warning: missing semicolon.
that line of code belongs to the function postStatus();
-
i have been testing my js script. and got some errors telling me that my function does not always return a value.
the two where
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);};
// new functionfunction replyToStatus(sid,user,ta,btn,document){ // 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; var ajax = ajaxObj("POST", "php_parsers/status_system2.php"); ajax.onreadystatechange = function() { if(ajaxReturn(ajax) === true) { var datArray = ajax.responseText.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(ajax.responseText); } } } ajax.send("action=status_reply&sid="+sid+"&user="+user+"&data="+data+"&document="+document);}
-
i've tried to change it.
when i post a new thread, no error occurs.
if i try to delete a thread, an errror occurs, it tells me that $_POST['document'] is undefined. Take a look.
$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>// 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);}// this is how status_system2.php looks likeif (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.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"; }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 it if($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(); }}
-
okay so i have tried to echo $_POST['document'] and its value is "watch", then i tried to echo $DB_table and it says "comments", but when i echo the $sql its gives me something completly different it says
"SELECT account_name, author FROM status WHERE id='53' LIMIT 1"
when really it should say
"SELECT account_name, author FROM comments WHERE id='53' LIMIT 1"
// fires of when the someone deletes a threadif (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.php if(isset($_POST['document']) && $_POST['document'] == "watch") // this means the user replied within watch.php { $DB_table = "comments"; } else if($_POST['document'] == "") // 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']; } echo $DB_table; // Check to make sure the person deleting this reply is either the account owner or the person who wrote it if($DB_table == null){ echo 'Can't look up nuthin'; exit(); }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"; echo $sql; $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) { mysqli_query($con, "DELETE FROM $DB_table WHERE osid='$statusid'"); echo "delete_ok"; exit(); }}
-
got this...
Error: this is an unexpected situation. What is happening?Can't look up nuthin<br /> // the custom error msg
and
Notice: Undefined variable: author in C:wampwwwphp_parsersstatus_system2.php on line <i>196</i>
what could possible be wrong?
-
i have a script that kinda works. Let me explain. This function is supposed to delete any post, but when i write a post, and then tries to delete it i get an error message. i says that i have an undefined variable $DB_table at line 180, then i close the error box, and click on "delete post" again, and then suddently the post is deleted from the DB
//this if statements give delete button to specified users// allows the author to delete threads they have made and the page owner to delete all threads if($check_document == "/watch.php") { if($author == $log_username || $account_name == $log_username ){ $statusDeleteButton = '<span id="sdb_'.$statusid.'"><a href="#" onclick="return false;" onmousedown="deleteStatus(''.$statusid.'','status_'.$statusid.'','watch');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> '; } } else if ($check_document == "/user.php") { if($author == $log_username || $account_name == $log_username ){ $statusDeleteButton = '<span id="sdb_'.$statusid.'"><a href="#" onclick="return false;" onmousedown="deleteStatus(''.$statusid.'','status_'.$statusid.'');" title="DELETE THIS STATUS AND ITS REPLIES">delete status</a></span> '; } }note: the first "$statusDeleteButton" has a function called deleteStatus with 4 parameters, but the second $statusDeleteButton's deleteStatus function only has 3 parameters.// Then i use ajax to comunicate with the server: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);}// this is from status_system2.phpif(isset($_POST['document']) && $_POST['document'] == "watch") // this means the user replied within watch.php { $DB_table = "comments"; } else if(!isset($_POST['document'])) // this mean that the user replied within user.php { $DB_table = "status"; } // Check to make sure the person deleting this reply is either the account owner or the person who wrote it $query = mysqli_query($con, "SELECT account_name, author FROM $DB_table WHERE id='$statusid' LIMIT 1"); while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $account_name = $row["account_name"]; $author = $row["author"]; }
// this is the error i get:
Notice: Undefined variable: DB_table in C:wampwwwphp_parsersstatus_system2.php on line <i>180</i>
ajax function doesnt run
in JavaScript
Posted
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
this function is used to reply a comment on an already existing thread