473,465 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to validate a form in php?

127 New Member
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
2 1481
Rabbit
12,516 Recognized Expert Moderator MVP
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
Januardi1793
1 New Member
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

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

Similar topics

1
by: Mattia | last post by:
Hi! I would like to validate a fiels in a form, but the code I wrote doesn't seem to work: HTML: <form name="formNome" method="post" action="/index.php" onSubmit="return...
5
by: Bunyip Bluegum | last post by:
I have a text field in a form which I need to check to see that only a 4-digit integer has been entered. The field has MAXLENGTH=4 and I'm using this to check for length: function...
1
by: mhawkins19 | last post by:
I have a form built and on the onclick event I validate all of the fields and then if the form is ok, on the submit event I run a javascript function to set a cookie and download a file from the...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
4
by: Wysiwyg | last post by:
I need to validate a form to ensure that all of the fields add up correctly. I can't do this while the user is entering data since validation needs to be done after the entry is completed. What's...
2
by: Adrian | last post by:
Hi everyone I have a web form where the validation works pefectly I copied the file, renamed it, and all of a sudden the validation stopped working(on the copied form). I have two panels on...
1
by: jayparaiso | last post by:
Hi! How to validate check box and drop down menu in one form?
2
by: Mick Walker | last post by:
Hi, I have a problem that I have been trying to figure for a couple of days, and am wondering if anyone out there would be so kind as to give me a solution. (Deadline time) I am trying to...
4
by: jmartmem | last post by:
Greetings, I have an ASP page containing a Record Insertion Form with a number of fields (mostly text fields and list/menu fields) linked to an Access database. I've created an onsubmit behavior...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.