Jump to content
xisto Community
Sign in to follow this  

Making Sure They Did Not Leave Any Required Fields Blank

Recommended Posts

how to make sure they did not leave any required fields blank?

<?php	include("config/config.inc.php");	include("config/dbcon.php");	include("checksession.php");			if(isset($_POST['action'])){		$gname = $_POST['gname'];		$gemail = $_POST['mail']; 		$gmsg = $_POST['gmsg'];		$date = date("m.d.y");$sql = "insert into tblguestbook ";$sql .= "(guestname, guestemail, guestmessage, guestdate)";$sql .=" values('$gname','$gemail','$gmsg','$date')";	mysql_query($sql);	}?><html><head><title>My Guestbook</title><link href="styles/style.css" rel="stylesheet" /><script language="javascript" src="includes/validate.js"></script><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><!--body {	background-color: #000000;}--></style></head><body><table width="100%" border="0" cellspacing="0" cellpadding="0">  <tr>	<td width="17%"> </td>	<td width="83%" valign="bottom" > </td>  </tr></table><form name = "form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" onSubmit="return validateForm(form1)">  <p class="fontSubTitle">Sign to Guestbook</p>  <p class="fontSubTitle"><span class="fontText">Name: </span>	<input type="text" name="gname">	<br>	<span class="fontText">Email:</span>	<input name="mail" type="text" id="mail">	<br>	<span class="fontText">Message:</span> 	<textarea cols="35" rows="6" name="gmsg"></textarea>  </p>  <p class="fontSubTitle">	<input type="submit" value="Send" name="action">	<input name="reset" type="reset" value="Clear">	<br>  </p></form>  <p>	<?php 	$results = mysql_query("select * from tblguestbook order by guestid desc");	while($data = mysql_fetch_object($results)){	echo "<table width=\"500\" border=\"0\" cellpadding=\"5\" cellspacing=\"1\" class=\"borderThin\" >";echo " <tr>\n";echo "<td class=\"fontTextTwo\" align=\"left\" width=\"60%\">name: ";echo "<a href=\"mailto:".$data->guestemail."\" class=\"b\">".$data->guestname."</a>";echo "</td>\n";			echo "<td class=\"fontTextTwo\" align=\"right\"  width=\"40%\">dated posted: ".$data->guestdate."</td>\n";echo "  </tr>\n";		  echo "<tr>\n";   		echo " <td colspan=\"2\" class=\"fontText\" align=\"left\">".$data->guestmessage."</td>\n";echo " </tr>\n";echo "</table><br>";	}	?></p></body></html><?php	mysql_close($dbh);?>
any help would be appreciated.

Share this post

Link to post
Share on other sites

If you want to check that something isn't empty use operator == .
Let's say you want to check your post['name'] to be empty, you can use

if (post['name'] !== "")

In this case if condition will only return true if post['name'] !== ""

Also you can use empty

if (!empty(post['name']) {

Will return true if your post['name'] is everything but empty.

To check your post['name'] even better, you can use regular expression

$pattern = '/[^a-z]/i';if(preg_match($pattern, $string)>0) {

returns true if there was some other character than letter

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.