im trying to compare a text field on my form to a colum in my mysql table if its one of the codes then submit the form if it isnt then display alert window? im new to php
Surely the form would have already been submitted - otherwise how will you know that the text field entry matches something in a database table?
Once you have delivered content to the web browser, the job of the PHP (web) server is finished. You can't continue to interact with it once it has delieverd the HTML to the web browser.
The same thing goes for the alert window... that's a Javascript (usually) event that cannot be triggered from the PHP server (for the reasons given above).
You could certainly do this using a combination of javascript and php, and you can do it without javascript if you are prepared to reload the page. If you are looking for php only solution, then you will need to re-think the flow.
I guess you could select the codes into an array, use in_array() on the array, and submit the data if the result is true, otherwise use javascript to send the alert.
example theory:
NOT real code, just example process
assume form has a $_POST array
// get codes from the database and load array
..
// check if the $_POST[whatever_code] is in the array
if(in_array($_POST[whatever], array)
insert into db
else
javascript alert ....
______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.