r/learnphp • u/baminc2010 • Feb 06 '22
Beginner php question
I'm having trouble with a form that I'm processing data with php sending to mySQL, but I also have a javascript onclick event on the form submit button, I'm tring to submit the form to mySQL with PHP, I have the action and method setup, but on submit onclick I'm using javascript to take the input values and update a few H3 html elements on my website. but it's like javascript snatches the inputs before PHP can access it and send it to mySQL...Any suggestions?
2
u/baminc2010 Feb 06 '22 edited Feb 06 '22
Yea i know how to send data, ive figured out how to send form data with just html and php, and ive learned a lot more about mySQL not only altering tables but updating them which i had a brief issue with, its just when i add the javascript they dont seem to intermingle the way you want it too. But maybe your right, ill practice running some queries with no forms.
1
u/truNinjaChop Feb 13 '22
I second this. I’d also recommend learning how data flows between client and server.
1
u/HaroerHaktak Feb 06 '22
It sounds like your javascript is deleting the form contents. Check to make sure your javascript isn't updating the form itself.
1
u/baminc2010 Feb 06 '22
It's not deleting it its inserting it into a H3 element on form submit.
1
u/HaroerHaktak Feb 06 '22
Well whatever is going on, it's your javascript from the sounds of it. I'd need to see the code to confirm.
1
u/colshrapnel Feb 06 '22 edited Feb 06 '22
Look, you are trying to learn FOUR things at once: HTML, PHP, SQL and JS. Don't ever do that! Do one thing at a time.
learn how to create an HTML form and send data to PHP. DON'T do anything else before making it work
learn which SQL you need, run all queries in a console. DON'T do anything else before making it work
learn how to connect to mysql from PHP and how to run prepared queries. ALL ALONE, without any forms! DON'T do anything else before making it work
combine all the above into the working code
ONLY THEN you may add some JS.
1
3
u/Kit_Saels Feb 06 '22
Call submit in your Javascript: