0

I'm creating variables on server 1 and then sending them via post to a mySQL database on server 2 using PHP file located on server 2.

Javascript on server 1...

$.post( "http://www.website.com/xxx/update.php", { vote:currentVote, page:currentmatch, round:roundNumber, team1: firstTeam, team2: secondTeam });

PHP to receive post, located on server 2...

$round = $_POST['round'];
//etc...

//I then set the query and insert the data, no problem.

After that, and on the same PHP file, counting rows and assigning total to variable...

$result = $connection->query("SELECT * FROM {$page} WHERE 'vote' = {$team1}")) {
    $team1Count = $result->num_rows;
}

How can I send that updated $team1Count variable back to the original page?

Thanks!

1

2 Answers 2

2

jQuery's .post() has a call back feature you can supply as an argument.

$.post( "http://www.website.com/xxx/update.php", { 
    vote:currentVote, 
    page:currentmatch, 
    round:roundNumber, 
    team1: firstTeam, 
    team2: secondTeam }, 
    function(data){
        //the call back, data contains your return from your php script
        console.log(data);
});

Just simply echo that variable from your php script

echo $team1Count;
Sign up to request clarification or add additional context in comments.

Comments

0

Try to echo the updated variable from the php. Something like this -

$result = $connection->query("SELECT * FROM {$page} WHERE 'vote' = {$team1}")) {
    $team1Count = $result->num_rows;
    echo $team1Count;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.