Trium918 Posted May 25, 2007 Share Posted May 25, 2007 Is it possible to validate chase switching? If so, what would be an example of the validation process? Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/ Share on other sites More sharing options...
Trium918 Posted May 25, 2007 Author Share Posted May 25, 2007 *bump* Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261510 Share on other sites More sharing options...
448191 Posted May 25, 2007 Share Posted May 25, 2007 Maybe someone could answer this if you explained what you mean by "validate chase switching". I'd say "validate case switching", but that doesn't make sense either. Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261537 Share on other sites More sharing options...
Trium918 Posted May 25, 2007 Author Share Posted May 25, 2007 Maybe someone could answer this if you explained what you mean by "validate chase switching". I'd say "validate case switching", but that doesn't make sense either. Is it possible to add some type of validation to the code below? I know that I can validate the form entries, but can there be some sort of validation added to the case switching example below? <?php $searchType = $_POST['searchType']; $searchTerm = $_POST['searchTerm']; switch($searchType) { case radio1: $sql = some query... break; case radio2: $sql = some different query... break; case radio3: $sql = some other different query... break; default: $sql = not NEEDED, but nice to have a backup } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261540 Share on other sites More sharing options...
448191 Posted May 25, 2007 Share Posted May 25, 2007 1) Strings go in quotes. You're comparing against constants now. 2) What do you mean by validation? The following could already be considered "validation". switch($searchType) { case 'sometype': $sql = some query... break; case 'someOtherType': $sql = some different query... break; default: trigger_error('Invalid type', E_USER_ERROR); } Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261546 Share on other sites More sharing options...
Trium918 Posted May 25, 2007 Author Share Posted May 25, 2007 Ok, I am trying to validate the script below which is inside a funtion. I am trying to get it to return a value <?php #Checks that username is in database $result = searchBy($variable) #Check error codes if($result == 0){ //No data } ?> <?php function searchBy(){ $searchType = $_POST['searchType']; $searchTerm = $_POST['searchTerm']; switch($searchType) { case radio1: $sql = "SELECT * FROM members_info WHERE user_name='$searchTerm'"; break; case radio2: $sql = "SELECT * FROM members_info WHERE email_address ='$searchTerm'"; break; case radio3: $sql = "SELECT * FROM members_address WHERE state ='$searchTerm'"; break; default: echo "There is a problem in your script"; } $res = mysql_query($sql); $num_results = mysql_num_rows($res); for ($i = 0; $i < $num_results; $i++) { $row = mysql_fetch_array($res); $user_name = $row["user_name"]; echo " <div class=\"friendtable\"> <table width=\"100%\" border=\"0\" cellspacing=\"0\"> <tr> <td class=\"image\"> <img src=\" \"> </td> <td class=\"info\"> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"> <tr> <td class=\"name\">Name:</td> <td class=\"name\">$user_name</td> <td class=\"actions\"><a style=\"text-decoration:none;\" href=\"http://\">View Profile</a></td> </tr> <tr> <td class=\"label\"> Network: </td> <td> <a href=\" \">Lander '09</a><br /> </td> <td class=\"actions\"> <a style=\"text-decoration:none;\" href=\"http://\">Send Message</a> <a style=\"text-decoration:none;\" href=\"\">Poke Dolores!</a> <a style=\"text-decoration:none;\" href=\"http://\">View Friends</a> <a style=\"text-decoration:none;\" href=\"http://\">Add to Friends</a> </td> </tr> </table> </td> </tr> </table> </div>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261567 Share on other sites More sharing options...
Trium918 Posted May 25, 2007 Author Share Posted May 25, 2007 If the searchTerm is not in the database return false How would I check to see if searchTerm is in the database by using the method below? <?php switch($searchType) { case radio1: $sql = "SELECT * FROM members_info WHERE user_name='$searchTerm'"; break; case radio2: $sql = "SELECT * FROM members_info WHERE email_address ='$searchTerm'"; break; case radio3: $sql = "SELECT * FROM members_address WHERE state ='$searchTerm'"; break; default: echo "There is a problem in your script"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261599 Share on other sites More sharing options...
per1os Posted May 25, 2007 Share Posted May 25, 2007 <?php switch($searchType) { case radio1: $sql = "SELECT * FROM members_info WHERE user_name='$searchTerm'"; break; case radio2: $sql = "SELECT * FROM members_info WHERE email_address ='$searchTerm'"; break; case radio3: $sql = "SELECT * FROM members_address WHERE state ='$searchTerm'"; break; default: echo "There is a problem in your script"; } $result = mysql_query($sql) OR DIE(mysql_error()); if (mysql_num_rows($result) < 1) { echo 'No results were found for ' . $searchTerm; } ?> Like that ??? Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261606 Share on other sites More sharing options...
Trium918 Posted May 25, 2007 Author Share Posted May 25, 2007 <?php switch($searchType) { case radio1: $sql = "SELECT * FROM members_info WHERE user_name='$searchTerm'"; break; case radio2: $sql = "SELECT * FROM members_info WHERE email_address ='$searchTerm'"; break; case radio3: $sql = "SELECT * FROM members_address WHERE state ='$searchTerm'"; break; default: echo "There is a problem in your script"; } $result = mysql_query($sql) OR DIE(mysql_error()); if (mysql_num_rows($result) < 1) { echo 'No results were found for ' . $searchTerm; } ?> Like that ??? Ok, how would I redirect the echo 'No results were found for ' . $searchTerm; string back to search.php page? <?php switch($searchType) { case radio1: $sql = "SELECT * FROM members_info WHERE user_name='$searchTerm'"; break; case radio2: $sql = "SELECT * FROM members_info WHERE email_address ='$searchTerm'"; break; case radio3: $sql = "SELECT * FROM members_address WHERE state ='$searchTerm'"; break; default: echo "There is a problem in your script"; } $result = mysql_query($sql) OR DIE(mysql_error()); if (mysql_num_rows($result) < 1) { header("Location: search.php"); //I need to return this back to search.php echo 'No results were found for ' . $searchTerm; exit; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52915-solved-validate-question/#findComment-261645 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.