DarkHavn Posted September 11, 2006 Share Posted September 11, 2006 Hey i'm doing a search, and im trying to figure out how to check if the feild was empty (if they just hit search and put nothing in the input feild in the form).heres my following code when the user submits the form [code]if(!empty($_POST['submitsearch'])){$_SESSION['access'] = true;connect();$keyword = strip_tags(stripslashes($_POST['search']));$newkey = $keyword . '_KW';//the query it's self//$query = "SELECT * FROM catalogue WHERE `keywords`='$newkey'" ;//The following takes the input from the feild and compares it to the values in keywords.//The next section is to take the id's of each result, and display them with their thumbnail image$_SESSION['keyword'] = $newkey;$query = "SELECT * FROM catalogue WHERE `keywords` LIKE '%$newkey%'"; //$query = "SELECT * FROM catalogue WHERE `keywords`='$keyword'";$result = mysql_query($query);if(mysql_num_rows($result) >= 1){$x = 0; while($rows = mysql_fetch_assoc($result)){ $x++;$values[$x] = $rows['identifier'];$_SESSION[$x] = $values[$x]; }// echo $rows['identifier'] . '<br/>';//$sqlquery = } else {echo "No results have been found";}}[/code]What im trying to do is, check if its empty if so, set a message or something like that.If it isnt, and there is a proper value, do the mysql queries etc.Can anyone steer me in the right direction?Cheers Link to comment https://forums.phpfreaks.com/topic/20368-checking-if-a-feild-was-empty/ Share on other sites More sharing options...
DarkHavn Posted September 11, 2006 Author Share Posted September 11, 2006 ah come on? please? Link to comment https://forums.phpfreaks.com/topic/20368-checking-if-a-feild-was-empty/#findComment-89706 Share on other sites More sharing options...
Wintergreen Posted September 11, 2006 Share Posted September 11, 2006 if(empty($_POST['element'])) { $_SESSION['message'] = "You need to blah blah"; header("Location: search.php");} Link to comment https://forums.phpfreaks.com/topic/20368-checking-if-a-feild-was-empty/#findComment-89712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.