troubleshooting Question

Can you use Javascript to check whether a form value already exists within a MYSQL table prior to submitting the form

Avatar of EICT
EICTFlag for United Kingdom of Great Britain and Northern Ireland asked on
JavaScriptPHPMySQL Server
15 Comments2 Solutions2411 ViewsLast Modified:
I have a PHP form which has dependent drop downs within it. Therefore I have the following javascript at the top of the page so it can refresh to form client side without submitting it.

<script language="JavaScript">
function autoSubmit()      
    var formObject = document.forms[\'theForm\'];

function process(){



The autoSubmit() function refreshes the form based on the drop down selections without submitting it.

The process() function submits the form only when the user is happy and presses the ‘Save’ button which actions this function.

The process() function then passes the form values to a separate PHP page called “close_pdp_process.php” which uses $_POST superglobal variable to collect the data and perform the necessary actions.

The problem I have it that I would like to check whether the ‘userid’ and ‘reviewdate’ primary key values already exist within the MYSQL table prior to opening the “close_pdp_process.php” page, so the user has an alert and can correct the form first.  

I was thinking that a check within the process() function would be appropriate. Like

function process(){

/////CHECK WHETHER KEY (userid, reviewdate) EXISTS IN TABLE  HERE  - If it does show alert, If not continue //////

I’m not sure how to do this as I would normally do the check using PHP. Can I mix PHP and Javascript in this way? Or is there a better solution?

Join our community to see this answer!
Unlock 2 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros