Jump to content


Photo

checking if a feild was empty


  • Please log in to reply
2 replies to this topic

#1 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 11 September 2006 - 08:48 AM

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

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";

}

}
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

#2 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 11 September 2006 - 09:35 AM

ah come on? please?

#3 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 11 September 2006 - 10:09 AM

if(empty($_POST['element'])) {
  $_SESSION['message'] = "You need to blah blah";
  header("Location: search.php");
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users