Try again later!

I have this code and its now working well. I keep on getting try again instead of, "OK, friend request send.

/*PHP CODE
********************************************************************/
$sql = “INSERT INTO hUserFriends(user1, user2, datemade) VALUES(’$log_username’,’$user’,now())”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “friend_request_sent”;
exit();

$friend_button = ‘Request As Friend’;
$block_button = ‘Block User’;

if($isFriend == true){
$friend_button = ‘Unfriend’;
} else if($user_ok == true && $u != $log_username && $ownerBlockViewer == false){
$friend_button = ‘Request As Friend’;
}

if($viewerBlockOwner == true){
$block_button = ‘Unblock User’;
} else if($user_ok == true && $u != $log_username){
$block_button = ‘Block User’;
}

/*JS CODE
*********************************************************************/

function friendToggle(type,user,elem){
var conf = confirm(“Press OK to confirm the '”+type+"’ action for user <?php echo $u; ?>.");
if(conf != true){
return false;
}
_(elem).innerHTML = ‘please wait …’;
var ajax = ajaxObj(“POST”, “php_parsers/friend_system.php”);
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == “friend_request_sent”){
_(elem).innerHTML = ‘OK Friend Request Sent’;
} else if(ajax.responseText == “unfriend_ok”){
_(elem).innerHTML = ‘Request As Friend’;
} else {
alert(ajax.responseText);
_(elem).innerHTML = ‘Try again later’;
}
}
}
ajax.send(“type=”+type+"&user="+user);
}
function blockToggle(type,blockee,elem){
var conf = confirm(“Press OK to confirm the '”+type+"’ action on user <?php echo $u; ?>.");
if(conf != true){
return false;
}
var elem = document.getElementById(elem);
elem.innerHTML = ‘please wait …’;
var ajax = ajaxObj(“POST”, “php_parsers/block_system.php”);
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == “blocked_ok”){
elem.innerHTML = ‘Unblock User’;
} else if(ajax.responseText == “unblocked_ok”){
elem.innerHTML = ‘Block User’;
} else {
alert(ajax.responseText);
elem.innerHTML = ‘Try again later’;
}
}
}
ajax.send(“type=”+type+"&blockee="+blockee);

Aside from these should be handled in functions, and it doesn’t look like you are checking to see the friend state before you do an insert, or even use prepared statements to protect your database:

You have an alert showing the ajax.responseText, what is getting returned? From the PHP code posted, it looks like you just insert the usernames, echo “friend_request_sent” (assuming the insert goes well every time), and then close the script out.

This is the rest of the code that would go with that section

[php]

<?php include_once("../php_includes/check_login_status.php"); if($user_ok != true || $log_username == "") { exit(); } ?><?php

if (isset($_POST[‘type’]) && isset($_POST[‘user’])){
$user = preg_replace(’#[^a-z0-9]#i’, ‘’, $_POST[‘user’]);
$sql = “SELECT COUNT(id) FROM hUsers WHERE username=’$user’ AND activated=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$exist_count = mysqli_fetch_row($query);
if($exist_count[0] < 1){
mysqli_close($dbConnect);
echo “$user does not exist.”;
exit();
}
if($_POST[‘type’] == “friend”){
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$user’ AND accepted=‘1’ OR user2=’$user’ AND accepted=‘1’”;
$query = mysqli_query($dbConnect, $sql);
$friend_count = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserBlocks WHERE blocker=’$user’ AND blockee=’$log_username’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$blockcount1 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserBlocks WHERE blocker=’$log_username’ AND blockee=’$user’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$blockcount2 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$log_username’ AND user2=’$user’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count1 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$user’ AND user2=’$log_username’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count2 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$log_username’ AND user2=’$user’ AND accepted=‘0’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count3 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$user’ AND user2=’$log_username’ AND accepted=‘0’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count4 = mysqli_fetch_row($query);
if($friend_count[0] > 99){
mysqli_close($dbConnect);
echo “$user currently has the maximum number of friends, and cannot accept more.”;
exit();
} else if($blockcount1[0] > 0){
mysqli_close($dbConnect);
echo “$user has you blocked, we cannot proceed.”;
exit();
} else if($blockcount2[0] > 0){
mysqli_close($dbConnect);
echo “You must first unblock $user in order to friend with them.”;
exit();
} else if ($row_count1[0] > 0 || $row_count2[0] > 0) {
mysqli_close($dbConnect);
echo “You are already friends with $user.”;
exit();
} else if ($row_count3[0] > 0) {
mysqli_close($dbConnect);
echo “You have a pending friend request already sent to $user.”;
exit();
} else if ($row_count4[0] > 0) {
mysqli_close($dbConnect);
echo “$user has requested to friend with you first. Check your friend requests.”;
exit();
} else {
$sql = “INSERT INTO hUserFriends(user1, user2, datemade) VALUES(’$log_username’,’$user’,now())”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “friend_request_sent”;
exit();
}
} else if($_POST[‘type’] == “unfriend”){
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$log_username’ AND user2=’$user’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count1 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$user’ AND user2=’$log_username’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count2 = mysqli_fetch_row($query);
if ($row_count1[0] > 0) {
$sql = “DELETE FROM hUserFriends WHERE user1=’$log_username’ AND user2=’$user’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “unfriend_ok”;
exit();
} else if ($row_count2[0] > 0) {
$sql = “DELETE FROM hUserFriends WHERE user1=’$user’ AND user2=’$log_username’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “unfriend_ok”;
exit();
} else {
mysqli_close($dbConnect);
echo “No friendship could be found between your account and $user, therefore we cannot unfriend you.”;
exit();
}
}
}
?><?php
if (isset($_POST[‘action’]) && isset($_POST[‘reqid’]) && isset($_POST[‘user1’])){
$reqid = preg_replace(’#[^0-9]#’, ‘’, $_POST[‘reqid’]);
$user = preg_replace(’#[^a-z0-9]#i’, ‘’, $_POST[‘user1’]);
$sql = “SELECT COUNT(id) FROM hUsers WHERE username=’$user’ AND activated=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$exist_count = mysqli_fetch_row($query);
if($exist_count[0] < 1){
mysqli_close($dbConnect);
echo “$user does not exist.”;
exit();
}
if($_POST[‘action’] == “accept”){
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$log_username’ AND user2=’$user’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count1 = mysqli_fetch_row($query);
$sql = “SELECT COUNT(id) FROM hUserFriends WHERE user1=’$user’ AND user2=’$log_username’ AND accepted=‘1’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
$row_count2 = mysqli_fetch_row($query);
if ($row_count1[0] > 0 || $row_count2[0] > 0) {
mysqli_close($dbConnect);
echo “You are already friends with $user.”;
exit();
} else {
$sql = “UPDATE hUserFriends SET accepted=‘1’ WHERE id=’$reqid’ AND user1=’$user’ AND user2=’$log_username’ LIMIT 1”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “accept_ok”;
exit();
}
} else if($_POST[‘action’] == “reject”){
mysqli_query($dbConnect, “DELETE FROM hUserFriends WHERE id=’$reqid’ AND user1=’$user’ AND user2=’$log_username’ AND accepted=‘0’ LIMIT 1”);
mysqli_close($dbConnect);
echo “reject_ok”;
exit();
}
}
?>
[/php]

That doesn’t answer my question. It shows even more that your code needs to be broken out into related methods or classes defined. As it stands now, it is a mess of code that would be a nightmare to maintain.

My original question:

You have an alert showing the ajax.responseText, what is getting returned?

the response im getting is Try again later

I don’t know if there is a language barrier or what, but no you are not getting “try again later” from the response. That may be what is displaying, but seeing as that string is not in the php file, you cannot be getting it as a response.

Oh sorry i must have missed read it. The alert sends off a check box that says “prevent this page from creating additional dialogs”

Does it say anything else? That is a typical alert prompt. What I am trying to determine is, what code block is being hit. You can figure that out by the return statement.

This are the codes being hit:
what im trying to figure out is why im not getting the ajax.responseText == “friend_request_sent”


Friend Button: <?php echo $friend_button; ?>


$friend_button = ‘Request As Friend’;

if($isFriend == true){
$friend_button = ‘Unfriend’;
} else if($user_ok == true && $u != $log_username && $ownerBlockViewer == false){
$friend_button = ‘Request As Friend’;
}


$sql = “INSERT INTO hUserFriends(user1, user2, datemade) VALUES(’$log_username’,’$user’,now())”;
$query = mysqli_query($dbConnect, $sql);
mysqli_close($dbConnect);
echo “friend_request_sent”;
exit();


_(elem).innerHTML = ‘please wait …’;
var ajax = ajaxObj(“POST”, “php_parsers/friend_system.php”);
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
if(ajax.responseText == “friend_request_sent”){
_(elem).innerHTML = ‘OK Friend Request Sent’;
} else if(ajax.responseText == “unfriend_ok”){
_(elem).innerHTML = ‘Request As Friend’;
} else {
alert(ajax.responseText);
_(elem).innerHTML = ‘Try again later’;
}
}
}
ajax.send(“type=”+type+"&user="+user);

Change this to the following:

[php]if($user_ok != true || $log_username == “”) {
echo ‘false’;
exit();
}
?>[/php]

So, you have verified that a new record was created? And there was not an error thrown when closing the database?

I am getting “false” in the alert(ajax.responseText)

So, it isn’t hitting what you think. It is actually exiting the script before anything else is done.

Thanks! I look over it

Hey i got it! thanks a lot!

Sponsor our Newsletter | Privacy Policy | Terms of Service