SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot karnetics's Avatar
    Join Date
    Dec 2004
    Location
    USA
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Need help validating form!!

    I am tring to put a stop function or something after my string " you have not entered your name. I am trying to keep from inserting a blank record into the database.

    if (empty($name)) {
    echo "<br />You have not entered your name.<br />";
    << the stop fuction need to go here>>

    ;
    } else {
    $name = $_POST['name'];
    echo "<br />Your name is $name<br />";
    echo "Your information has been log into our database.<br />";

    }

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wold do something like this
    HTML Code:
    <?php
    $msg = null;
    if(isset($_POST['name']))
    {
     if(empty($_POST['name']))
     {
      $msg = 'Please enter name.';
     }
     else
     {
       $name = $_POST['name'];
      //now do your inserting into database stuff
       $msg = 'Record inserted.';
     }
    }
    ?>
    <form name="whatever" method="post" action="<?php echo 
    $_SERVER['PHP_SELF'];?>">
    <?php echo $msg;?>
    <input type="text" name="name" value=""> etc. etc.
    
    <form>
    so this way it will generate an error message and echo if the error message is there or will insert the record into database.

    but if you want to put stop function then i think you are asking
    die('your message') ;
    or
    exit;

  3. #3
    SitePoint Zealot karnetics's Avatar
    Join Date
    Dec 2004
    Location
    USA
    Posts
    179
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jaswinder_rana
    i wold do something like this
    HTML Code:
    <?php
    $msg = null;
    if(isset($_POST['name']))
    {
     if(empty($_POST['name']))
     {
      $msg = 'Please enter name.';
     }
     else
     {
       $name = $_POST['name'];
      //now do your inserting into database stuff
       $msg = 'Record inserted.';
     }
    }
    ?>
    <form name="whatever" method="post" action="<?php echo 
    $_SERVER['PHP_SELF'];?>">
    <?php echo $msg;?>
    <input type="text" name="name" value=""> etc. etc.
    
    <form>
    so this way it will generate an error message and echo if the error message is there or will insert the record into database.

    but if you want to put stop function then i think you are asking
    die('your message') ;
    or
    exit;
    Thanks that worked...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •