Web Analytics Made Easy -
StatCounter Empty values posting - CodingForum

Announcement

Collapse
No announcement yet.

Empty values posting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Empty values posting

    ok I can get my form to post with no problem, but I can't seem to get it to NOT post if a field is empty...

    form html:

    Code:
    	<form action="<? echo $_SESSION['PHP_SELF'] ?>" method="post">
    	<p>
    	<label for="author">Author:  </label>
    	<input type="text" size="40" name="author"  value="<? echo $row['UserFirstName'] . " " . $row['UserLastName']; ?>" />
    	</p>
    	<p>
    	<label for="title">Title:  </label>
    	<input type="text" size="40" name="PostTitle" value="<? echo $_POST['PostTitle']; ?>" />
    	</p>
    	<p>
    	<label for="content">Message:  </label>
    	<textarea cols="40" rows="10" name="PostContent" value="<? echo $_POST['PostContent']; ?>"></textarea>
    	</p>
    	<p>
    	<input type="submit" name="add" value="Add Comment" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" name="reset" value="Start Over" />
    	</p>
    	</form>
    insert query:

    PHP Code:
            $author=$row['UserFirstName'] . " " $row['UserLastName'];
            
    $title=$_POST['PostTitle'];
            
    $content=$_POST['PostContent'];
            
    $error=array();

            if (isset(
    $_POST['add']))
                {

                    if (
    strlen(trim($_POST[$author]))==0)
                    {
                    
    $error['author'] = 'Please enter your name.';
                    }
                
                    if (
    strlen(trim($_POST[$title]))==0)
                    {
                    
    $error['title'] = 'Please enter a title.';
                    }

                    if (
    strlen(trim($_POST[$content]))==0)
                    {
                    
    $error['content'] = 'Please enter a comment.';
                    }

                    if (
    count($errors)==0)
                    {
                    
    $query="INSERT INTO tblSCIBlog (PostDate, PostAuthor, PostTitle, PostContent) VALUES (CURRENT_DATE(), '$author', '$title', '$content')";
                    
    $result=mysql_query($query);
                    
                        if(
    $result)
                        {
                        echo 
    "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">Your blog entry has been submitted.</p>";
                        }
                        
    mysql_close($conn);
                    }

                else
                    {
                    foreach(
    $error as $err)
                        {
                        echo 
    "<p style=\"color:#ff0000;font-weight:bold;font-size:14px;\">" $err "</p>";
                        }
                    }

                } 
    unfortunately I think it's something with my variables but I just can't figure out which one it is

    any help is greatly appreciated

  • #2
    Hi,

    Your errors variable is named $error and you're doing a check with:
    if (count($errors)==0)

    Remove the s and give it a go

    good luck;
    -Brando
    Why using tables for eating is stupid!

    Comment


    • #3
      Resolved

      yes I did have a bad variable...

      if (count($errors)==0)

      the variable is actually $error

      Comment

      Working...
      X