I need help with PHP AJAX

dannywebnoob

New member
Registered
Joined
Aug 25, 2021
Messages
2
Points
1
hey guys
I need help with AJAX. I want to UPDATE my DB without refreshing. I don't really know how to do this. I have found piece of code online but for some reason is not working. Another thing is : how to make run PHP code after 5 minutes. For example: someone push the button and after 5 minutes my DB will be updated. Any Ideas?
 

Dopani

Well-known member
Registered
Joined
Mar 11, 2014
Messages
158
Points
18
It is easy mate!

Check example here https://www.w3schools.com/php/php_ajax_database.asp

Their codes

<html>
<head>
<script>
function showUser(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("txtHint").innerHTML = this.responseText;
}
};
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
}
</script>
</head>
<body>

<form>
<select name="users" onchange="showUser(this.value)">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Joseph Swanson</option>
<option value="4">Glenn Quagmire</option>
</select>
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>

</body>
</html>
In getuser.php file, you need to make the Mysql query to return the string and display it in txtHint div by ID

Hope that helps!
 

lindasil

Member
Registered
Joined
Jun 11, 2020
Messages
20
Points
1
There are a number of different types of web design https://mlsdev.com/blog/top-custom-software-development-companies , from professional to commercial. In fact, many web developers do not even use a professional web design, but instead develop something for themselves that will only be used for the website. One type of web design is called the freeware web design, which is available free of charge. Many companies offer free conversion templates that web designers can use to construct their site. Another type of web design is the shareware web design, which is offered free but has limited features. Finally, there is the paid web design, which is offered either as a freeware or shareware program and which comes with several limits and restrictions.
 
Last edited:

S4 Hosting

Active member
Moderator
Hosting Provider
Joined
Mar 5, 2021
Messages
72
Points
6
Another thing is : how to make run PHP code after 5 minutes. For example: someone push the button and after 5 minutes my DB will be updated. Any Ideas?
I'm curious, what is the use case for this, what are you trying to achieve?

I don't see any reason why you would want to update something in a database with that much delay. I can think of possible reasons to not show something being updated to frontend viewers for a while, but not to actually not update it, it introduces all sorts of potential issues with the server going down or other failure during the time period between click and update.
 
Latest Threads
Recommended Threads
Replies
1
Views
2,118
Replies
6
Views
1,094
Replies
10
Views
2,957

Sponsors

Latest Blog ArticlesMost Viewed Threads

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top