Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Making Sure They Did Not Leave Any Required Fields Blank
dvayne
post Nov 9 2007, 09:40 AM
Post #1


Newbie [Level 1]
*

Group: Members
Posts: 11
Joined: 28-October 07
Member No.: 52,165



how to make sure they did not leave any required fields blank?
CODE
<?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%">&nbsp;</td>
    <td width="83%" valign="bottom" >&nbsp;</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.
Go to the top of the page
 
+Quote Post
pop
post Nov 9 2007, 12:03 PM
Post #2


Advanced Member
*******

Group: Members
Posts: 101
Joined: 13-October 07
Member No.: 51,530



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

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


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

Also you can use empty

CODE
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

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


returns true if there was some other character than letter
Go to the top of the page
 
+Quote Post
gogoily
post Dec 11 2007, 05:49 AM
Post #3


Member [Level 3]
******

Group: Members
Posts: 99
Joined: 30-October 05
Member No.: 13,571



I add one tips:

CODE
if(preg_match("/^\s*$/",$string))
{
    die("Sorry, but all fileds must be filled !");
}


This code can prevent any kind of blank, including spacing.
Go to the top of the page
 
+Quote Post
online
post Dec 20 2007, 07:53 PM
Post #4


Newbie
*

Group: Members
Posts: 4
Joined: 20-December 07
Member No.: 55,063



for examle... (i make this simple)
CODE
<?php
if($_GET['act'] == 'fields')
{
echo "<br><b>Please fill in all the fields.</b><br>";
}

if($message == '')
{
header("location:?do=&act=fields");
exit;
}
?>
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Personal Blog(4)
  2. Blocking Pages & Making Ranks(4)
  3. Intranet Search Engine(4)
  4. How To Make Oscommerce Work With Phpbb(1)
  5. Some Php Functions Explaination Required(2)
  6. Php Code Fix Required(3)
  7. Files Required?(5)
  8. Making A Sig With Php(7)
  9. Making A New Bbcode For Smf 1.09(0)
  10. Making This Compatable With Trap17's Php(2)
  11. How To Delete A Row In Mysql.(4)
  12. Blank/duplicate Entries(5)
  13. What Coding Languages Are Required?(5)
  14. Blank Cookies...(4)
  15. [php] Hidden Fields?(4)
  1. Script Help Required: Undefined Variable(3)
  2. How Would I Go About Making A Simple "counting" Script?(3)


 



- Lo-Fi Version Time is now: 12th October 2008 - 03:32 AM