I am currently working on a fun project, which involves Ajax, HTML, JavaScript, PHP and SQL.
I have debugged my project as far as I could, and I am 100% sure my AJAX, HTML and JavaScript are working fine and my variables are send to the server correctly.
I am trying to fetch data from the database, subtract a number (submitted in the form) from this data and update the database accordingly.
My database does update. However, it is not displaying the correct numbers. When submitting 1 in the form, it will ALWAYS return the same numbers in the database. (Which is odd, because I am subtracting it…). I am 100% sure the data from the form is passed to the server correctly, so I would like you all to check my server file, which should be the problem.
Edit:
The database connection is made in db.php and is made correctly. This has been tested.
You really need to switch to prepared statements to fix your sql injection problems.
Apart from that, what’s wrong with this specific code, is that
mysql_querydoes not return a number, it returns a resource. You need to fetch a row to get the number.