tmharrison Posted February 7, 2007 Share Posted February 7, 2007 I have my main website. www.mysite.com it has a tour number field on it, and it is working fine, however i would like to have javascript alerts when they either leave the field blank or the tour number doesn't exist in the database. I have the alerts on my php page already. anyway, i am ok with the way that it is, however, when i click the OK on the javascript alert message it continues to go onto my gotoTour.php script. (which is listed below) <?php ob_start(); if (!empty($_POST['id_num'])) { require_once ('/home/virttcom/public_html/VHDdb/mysql_connect.php'); // Clean the $_POST['id_num'] to avoid sql injection if(get_magic_quotes_gpc()) { $_POST['id_num'] = stripslashes($_POST['id_num']); } $_POST['id_num'] = mysql_real_escape_string($_POST['id_num']); $q = "SELECT url FROM Tours WHERE id_num='{$_POST['id_num']}'"; $get_url = mysql_query($q) or die("There was a problem with the query: $q" . mysql_error()); if (mysql_num_rows($get_url) > 0) { $rw = mysql_fetch_assoc($get_url); $url = $rw['url']; // Redirect the user header("location:$url"); } else { echo "<script language=\"javascript\"> alert('We do not carry this Virtual Tour, call your Agent and ask them to use Virtual Tours'); </script>"; } } else { echo "<script language=\"javascript\"> alert('Virtual Tour Numbers are six numeric digits only. Please check your number and try again.'); </script>"; } ob_end_flush(); ?> How can I get it to stop continuing to go to this php page, and just show the alert message on my main page www.mysite.com Much appreciated, i've been messing with this all night now, i have tried everything been on every javascript site there is to figure it out, i am stuck. Thanks again for your help Tina Quote Link to comment Share on other sites More sharing options...
artacus Posted February 7, 2007 Share Posted February 7, 2007 Well one option is to check it before it is submitted using AJAX. If you check it after it has already been submitted, then do something like this: echo "<script language=\"javascript\"> alert('We do not carry this Virtual Tour, call your Agent and ask them to use Virtual Tours'); history.go(-1); // or document.location.href = 'wherever.php'; </script>"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.