Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I script a friend request using php/ajax/jquery?
    primarykey
    data
    text
    <p>I would appreciate help with this script:</p> <p>I have this script on a page called members, what I want this script to do is when a member, let's say member A, sends a friends request by clicking the button, first the status changes to something say 'requesting...', then the script sends the request to php via the script this is what I have:</p> <pre><code> &lt;script type="text/javascript"&gt; var email_cont = '&lt;?=$mem_com[email]?&gt;'; var cont_email = '&lt;?=$_SESSION[email]?&gt;'; $('#connectButton').click(function() { var counter = 0; $.ajax({ url: 'requests.php? cont_email='+cont_email+'&amp;email_cont='+email_cont+'&amp;counter='+counter, success: function( data ) { $('#connectButton').val(data); // set the button value to the new status. $('#connectButton').unbind('click'); } }); }); &lt;/script&gt; </code></pre> <p>For clarity:</p> <ul> <li>the button has a default values called form the database.</li> <li>cont_email is the email of the member sending request</li> <li>email_status is the email receiving the request</li> <li>counter is the request count for every request sent to the members</li> </ul> <p>However, my problem with script is that it only allows for one click on the request button as there are more than one posts from members on the page as it changes the status for all members even when a particular member have not sent any request. ie members A sends request to B, the status should show that request has been sent but however members C login the status of Member A/B request is still display, I want a way to make the status exclusive to each members, status should only show for a particular memeber if request has been sent else the status bears the default value.</p> <p>Here is my PHP code:</p> <pre><code>$email_cont = $_GET['email_cont']; $cont_email = $_GET['cont_email']; $counter = $_GET['counter']; $status = "Connection Sent!"; $insert = mysql_query("INSERT INTO reqst VALUES ('','$cont_email','$email_cont','$status', '$counter', NOW())"); if(!$insert) { //If it fails to run the SQL return an error. echo "Connection Failed!"; } else { $update = mysql_query("UPDATE upd SET request ='$status' WHERE email ='$email_cont'"); //If all goes well, return the status echo $request; } </code></pre> <p>I need a way to separate the request made by member A to B from members B to C so that the $update only update the table called upd status for A to B while B and C or C to D maintains the default values as no request is sent yet. so that when the $request is echoed it only carry the request status of the members according to the request status, ie X if request is made, Y if no request is made, Z if request is accepted .</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload