how to validate a form in php?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • impin
    New Member
    • Jul 2010
    • 127

    how to validate a form in php?

    how to validate this form. when user submits without selecting the options, must get a alert.

    my code

    Code:
    echo "<form method='post' id='submit' action='checkresult.php'>";
    $sql="SELECT * FROM cquestions where showdate='$today' limit 2";
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result)) {
    echo "<p>" . $row['cqtext'] . "</p>";
    $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
    $result2=mysql_query($sql2);
    while($row2=mysql_fetch_assoc($result2))
    {
    echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext']; }
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    In the page that it is submitted to, check that the fields were filled out and echo an error message if it wasn't complete.

    Comment

    • Januardi1793
      New Member
      • May 2013
      • 1

      #3
      You can use html, put "required" into tag input

      like this :
      Code:
      echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' required />".$row2['aatext'];

      Comment

      Working...