violinrocker Posted May 27, 2011 Share Posted May 27, 2011 I cant seem to post 'sub'... 'comment' is posted but sub is not... what is wrong with my code? $('.comment_button').live("click",function() { var ID = $(this).attr("id"); var comment= $("#ctextarea"+ID).val(); var sub= $("#csub"+ID).val(); var dataString = 'comment='+ comment + '&msg_id=' + ID + '&sub=' + sub; if(comment=='') { alert("Please Enter Comment Text"); } else { $.ajax({ type: "POST", url: "extra/comment_ajax.php", data: dataString, cache: false, success: function(html){ $("#commentload"+ID).append(html); $("#ctextarea"+ID).val(''); $("#ctextarea"+ID).focus(); } }); } return false; }); this is my form <form method=\"post\" action=\"\"> <input type='text' name=\"comment\" class=\"comment\" maxlength=\"200\" id=\"ctextarea$msg_id\" style=\"float:left;width:400px;padding:1px\" ></input> <input type='hidden' name=\"sub\" id=\"csub$msg_id\" class=\"comment\" value='$sub'></input> <input type=\"submit\" value=\" Comment \" id=\"$msg_id\" class=\"comment_button small green awesome\" style=\"float:left;padding:2px\"/> </form> Link to comment https://forums.phpfreaks.com/topic/237609-_post/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 The only thing that stands out in what you posted is that there is no </input> closing tag and the two you have should be removed. Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1220985 Share on other sites More sharing options...
violinrocker Posted May 27, 2011 Author Share Posted May 27, 2011 i removed </input> but it still doesnt post it. i think i may have something wrong in here var comment= $("#ctextarea"+ID).val(); var sub= $("#csub"+ID).val(); var dataString = 'comment='+ comment + '&msg_id=' + ID + '&sub=' + sub; or here <input type='hidden' name="sub" id="csub$msg_id" class="comment" value='$sub'> Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1220987 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 Without actually testing what you did post, the problem is fairly likely to be in your comment_ajax.php code. Posting that and posting all of the form page would help because it would allow someone to both see and test your actual code. Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221000 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 I just tested the code you posted (writing the content of the $_POST array to a file) and your posted code sends the comment, msg_id, and sub values. Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221002 Share on other sites More sharing options...
violinrocker Posted May 27, 2011 Author Share Posted May 27, 2011 this is whats on my comment_ajax page (without the included files) if(isSet($_POST['comment'])) { if($POST['sub']==1){ cominsert($session->username,$POST['comment'],$_POST['msg_id']); } else{ subcominsert($session->username,$POST['comment'],$_POST['msg_id']);} i tried changing $_POST[msg_id] to $POST['sub'] to see if the value for sub can be inserted into the database, but it inserts nothing Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221003 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 Have you checked in the 'view source' of your form page if the hidden sub field even has the value you expect? Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221055 Share on other sites More sharing options...
violinrocker Posted May 27, 2011 Author Share Posted May 27, 2011 ^ haha thanks for the tip, instead of $_POST i had $POST ... thanks so much for the replies i really appreciate it Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221061 Share on other sites More sharing options...
PFMaBiSmAd Posted May 27, 2011 Share Posted May 27, 2011 You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed. The $POST variables would have produced undefined... error messages that would have helped you to find them. Link to comment https://forums.phpfreaks.com/topic/237609-_post/#findComment-1221065 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.