How to take inputs from 2 different users? AJAX [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want 2 different users to pass these 2 values.
Thats means num1 will contain the value which is send by user1 and num2 containing user2's value.
In general, I just want 2 users interacting with each other.
How should I code it??

Call a page through ajax say getuser.php
$.ajax
({
type: "POST",
url: "getuser.php",
success: function(result)
{
console.log(result); // here you will get logged in user session id
}
});
getuser.php
<?php
session_start();
echo $_SESSION['id']; // Assuming your session name is id
?>
OR
If you want user details of logged in user, then you can fetch from database against the session id.

Related

Trying to make user follow another and show notification [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am creating a website in codeigniter and i wants to give a functionality of following other user account. How can I refresh the code using ajax after some specified time? So can somebody give me some easy suggestion to do that with ajax?
You can create a table notification. When a user followed by another user. You add data in notification table. Table structure is as follows
id int
image text if you need to show image with notification.
title text Eg. Ram followed you.
link text Link on which you want to redirect.
notification_for text user_id of user (sometimes notification is for multiple users)
login_type text I use this table for admin/front panel. So I've to use this
created_date datetime
created_by int
updated_date datetime
updated_by int
status int
jQuery Code
$(document).ready(function(e){ getnotification();});
function getnotification(){
$.ajax({
url : path/to/post,
type : 'POST',
data : {'id':id},
success : function(e) {
window.setInterval(function(){getnotification();}, 5000);//run after 5 seconds
},
});
}

insert MySQL row on page load [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
This is going to be my first question on stackoverflow so I hope I'm doing it right =)
I want to insert a MySQL record when the page loads.
I have a form and a database. I want to be able to see in my database if the user has visited the form page( obviously without submitting the form ).
I know how to do it on page submit, but how can I fill up a MySQL row on page load?
Example of my wish:
example
I'm very curious how this can be done . Thanks in advance!
You need to use AJAX for this kind of stuff..
update.php
<?php
mysqli_query("INSERT INTO bla (column1, column2) VALUES (value1, value2)") or die(mysqli_error());
?>
jQuery:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "update.php"
success: function(data) {
// success
}
});
});
This is a really basic way, you could use "$_GET" to send data in your AJAX request etc.
-
Edit: #David had a fair point in the comments. Try that first.

Updating contents without refreshing? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to update a division of my webpage updated frequently. But the contents of the division is to be loaded from another file on the server which is unable to be accessed from the file. I have made the access for the first time through PHP on the server. When I'm updating the information, the javascript is on client-side and I'm unable to access it.Also, the meta tag refreshes the entire webpage. I just want to update the division
What are the ways to solve this problem?
You could do this with jQuery and AJAX
like this:
$.get('/route/to/file', { args }, function(data) {
$('#some-container').html(data);
});
If you need it to be fully realtime, you could also use Socket.io:
var ws = io( ... );
ws.on('some.realtime.event', function(data) {
$('#some-container').html(data);
});

How to send data from one page to other page in php when the user clicks on the displaying value as said below [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am reading names from xml and displaying on php page.how to send this names to another page when user clicks on any name,and how can i save that name in another page till user clicks other value???
You can call ajax.
<script type="text/javascript">
jQuery(function($){
var field1 = $('#field1');
$('#send').click(function(){
/* Enter your code */
jQuery.ajax({
url: 'somepage.php',
type: 'post',
data: 'field1value=' + field1.val(),
success: function(results){
alert(results);
}
});
});
});
</script>
this seems like a task for AJAX. But this means you need to program at least in JavaScript or JQuery for that.
Take a look here at this example: http://www.w3schools.com/jquery/jquery_ajax_get_post.asp
Greetz
For 1st, you can pass the name in url by using any variable.
For example: www.xyx.com?name=your_selected_name
For 2nd, You can save the clicked value in session variable. when other value is clicked, unset the previous value.

Simultaneously adding points and linking [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
i got this simple points system, where when a user clicks on the image it adds 20 points to the database through a mysql query. It works, however, I'm trying to make it so that when a user clicks on the image that it not only adds points to a users database but also goes to a website. I added correctly but then it links but doesn't add points. Any help would be appreciated.
Use Ajax for inserting points in your database and after response(in your success method) send it to your desired URL.
$.ajax({
type: "POST",
url: '/test/points.php',
data: formData,
success: function (dataCheck) {
if (dataCheck) {
window.location = 'www.example.com';
}
}
});

Categories