Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Look up

Status
Not open for further replies.

nycepete

Programmer
Sep 28, 2005
13
US
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

any examples or tutorials on my code above?


thanks
Pete

 
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.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top