MySQL database change on button click html - javascript

I am new to HTML, and im trying to do something very simple:
There is a "code" in Mysql database with a value of 100.
In the HTML page there is a place where you enter the code, and if its correct it loads the Value and shows it on the page (which is 100).
There is a button, when you click on it, it takes away 5 from the value and saves it in the MYSQL database.
When you refresh the page and enter the code again,it loads the value and shows: 95.
How do i create this?
Im having hard time with this.
Thank you for your help.

Related

Unable to fetch id valuse in Java script

enter image description here
enter image description here
enter image description here
Hi there,
I am trying to create two buttons save and update where the difference between them is the save button will save the data navigate to the back page and the update button will save the data and will stay on the same page.
I am not sure where I am going wrong but I am unable to fetch the id in the if condition of Java Script.
Thanks in advance.

Play an alarm with the table value in webapge

I have a webpage containing a table that auto-refresh everytime & updates the table values. I want to add an alarm when the table value reached a threshold value so I don't have to look at the table always. what is the best possible way to do this?
My webpage is updating data using PHP. I know this is somewhat possible using javascript. Also, I found there is a limitation in doing this without a user gesture
i found another post with something similar and if your refreshing all the time then you could make a PHP if else statement to check database values and run the audio.
if ($value > 10){play audio}else{nothing}
Play a sound on page load using JavaScript

Form doesn't submit without refresh (please Vanilla JS only)

I know this is a bit tricky because I can't actually post the JS or HTML code but I'll try my best to describe it.
So basically I created a table with JS on the HTML.
Then I use "submit" and "form" in the html to submit content onto the table. The content is retrieved with fetch and an API.
The issue I have is that while it all works well, the data doesn't appear on the table without me having to refresh the browser. I'd the data to appear as soon as I click the submit button.
Cheers and thanks in advance
Its obvious and correct to dont show new records because table just can show last result of request .
For your goal you can reload just table tag with ajax or other ways for example you can refresh table tag x second after click on submit button.(x should be enough big that new records has time to submit).

Wordpress calculator form without resubmit and using custom field value

I am currently trying to solve a problem on my Wordpress website. I do not have any code just yet (as I have re-written 4 different forms before I gave up), so I will just state what I want to do, I am pretty sure it's quite simple and I'm just missing something.
I need to build a form on the front-end that works like this: user inputs some value, chooses some other value from dropdown, than clicks on the submit button, page does NOT reload, instead a value is calculated and shown (I know how to show a value after click using jQuery), BUT the value that will be shown is calculated using not only form inputs and hardcoded variables, but also Wordpress custom field values using PHP function get_field().
The problem is that if I use ajax to get values from the form without reloading the page, those values are in javascript and I need to use them with PHP get_field() function.
So, to repeat what I intend to do, so It's easier to understand more quickly:
Form where user inputs some values
User clicks submit
The page does not reload
New value is calculated based on user input and custom field value (using get_field())
New DIV is shown using JQuery on submit click (I know how to do this one, but its important because this is the reason why the page must not be reloaded).
If you could just point me in the right direction, I will be able to code everything else.
Why not just inject the custom fields inside javascript variables when building the page template in php? Then you would have all the data available in javascript when the page loads. Something like this:
<?php
echo '
<script type="text/javascript">
var custom_field_1 = '.json_encode(get_field('custom_field_1')).';
var custom_field_2 = '.json_encode(get_field('custom_field_2')).';
</script>
';
?>

Send an alert from an open page to another (php, javascript, html)

I am developing a website that has a receptionist page and a user page with multiple user logins. The logged in users are displayed in a table at the receptionist page and one of the columns of the table is the status of the user ( ready or busy). The table is refreshed using ajax every 5 seconds to prevent the web page from refreshing. Each user can log in ( with thier own page) and change their status( ready to busy or busy to ready).
The table is stored in a sql database.
The user page has the option to change the state of the logged in user from ready to busy ( or vice verse) with a drop down menu and a submit button. What i need is to also send and alert or sound to the receptionist page whenever any user switches to the ready state.
I have looked all over the internet but none of the answers have worked for me.
Thanks for your replies. I understand that I could use ajax to query the database to see if a user is ready, however that will cause it to make a notification every time it checks. What i need is for the receptionist to be notified only 1 time each time that a user sets status to ready. I was thinking of making another table that gets updated every time a user changes their status to ready and time stamp it. So that if there is a change in the time stamp it means that some one newly updated it so the signal should be sent.
I made the table and made a php page that returns a string with the time stamp of the table but i dont know how to use the returned string in java script.
I figured it out. I made an SQL table with a time stamp, whenever any user sets their status to ready the time stamp gets updated. I made a java script that reads the time stamp every few seconds. If the time stamp is different than the initial time stamp then a sound is played.
#O.Rases gave you the best solution.I did something like this in past using ajax and php.
A solution can be the following.
1 Every 10s, sent a Ajax call to the server.
2 In the server, using php, you can select users that changed their status in the last 11s (+1s for time-consuming script in the server).
3 after selection is done, sent the user back to the receptionist page.
hope it helps

Categories

Resources