insert MySQL row on page load [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 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.

Related

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.

How to take inputs from 2 different users? AJAX [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 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.

Simple way to count clicks with jquery, mysql and ajax [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 9 years ago.
Improve this question
My question to save time:
What is the simplest way to count clicks of a button, save that value to a Wordpress MySQL db and retrieve that updated total number into a div with Ajax, so the page doesn't need to up reloaded to see it?
I'm just learning how to dive into more UX glory with added mysql db support and Ajax updates with jQuery as the driving force.
My knowledge of working with databases in general is... green to say the least.
I have another question going, but I thought I'd open this up as a more general question. I see lots of tutorials online, but not a lot of elegant, minimal code like I know I've learnt here on SO already.
OP is here: Counting clicks with jQuery and displaying with Ajax
You can bind to the button's click event and then tell your server-side logic to increment the count in the database, like this:
$("#YourButton").click(function() {
$.ajax({
url: '/PathToServerSide',
type: 'POST',
data: {increment: true},
success: function(data) {
alert('Server click count updated!')
}
});
}
Note: Never trust the client-side to tell the server-side what the count value is, but instead send a command (increment) to tell the server-side logic to increment the value in the database.
To display the amount of clicks, use the data returned from the AJAX success callback and the jQuery .html() function, like this:
$('#YourCounter').html('The button has been clicked ' + data + ' times`);

Passing form entries to query a database passed and updated to a div tag using AJAX [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to create a page with an AJAX style form. Where on submit, the values in the form search and query a database and output the search results into the same DIV as the form was.
Any help would be much appreciated.
Thanks
jQuery is probably what you're looking for...
The docs are straightforward. http://jquery.com/
Generally, jQuery follows the find something then do something approach.
Find something ---> watch for some action on some element (in your
case, clicking submit)
Do something ---> make an ajax call to the php page you want to run
the query and return the results then insert the results where you
want on the page
http://api.jquery.com/jQuery.post/
Some other helpful jQuery commands for this task could be...
http://api.jquery.com/appendTo/
http://api.jquery.com/remove/
http://api.jquery.com/append/
Hope this helps.

Categories