By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,818 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,818 IT Pros & Developers. It's quick & easy.

how to validate a form in php?

100+
P: 127
how to validate this form. when user submits without selecting the options, must get a alert.

my code

Expand|Select|Wrap|Line Numbers
  1. echo "<form method='post' id='submit' action='checkresult.php'>";
  2. $sql="SELECT * FROM cquestions where showdate='$today' limit 2";
  3. $result=mysql_query($sql);
  4. while ($row = mysql_fetch_array($result)) {
  5. echo "<p>" . $row['cqtext'] . "</p>";
  6. $sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
  7. $result2=mysql_query($sql2);
  8. while($row2=mysql_fetch_assoc($result2))
  9. {
  10. echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext']; }
  11. }
  12.  
May 24 '13 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,364
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.
May 24 '13 #2

P: 1
You can use html, put "required" into tag input

like this :
Expand|Select|Wrap|Line Numbers
  1. echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' required />".$row2['aatext'];
May 30 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.