473,383 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

form validation

Hi all,
I want to learn about server side form validation.I have the following source code. But i dont know the meaning of $_SERVER['PHP_SELF']. When i ran this code it shows an error. The error says multiple choice.

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4.  <head>
  5.   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6.   <title>New HTML Document</title>
  7.  </head>
  8.  <body>
  9.  <?php
  10.    if(isset($_POST['posted'])){
  11.      if($_POST['q1']=="answer1" && $_POST['q2']=="answer2")
  12.       echo  "Right" ;
  13.      else echo "Wrong";
  14.    }
  15.  
  16.    ?>
  17.   <form  method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  18.   <input type="hidden" name="posted" value="true">
  19.   What is the answer of first question?
  20.   <br>
  21.   <input type="radio" name="q1" value="answer1">Answer1
  22.   <br> 
  23.   <br>
  24.   <input type="radio" name="q1" value="answer2">Answer2
  25.   <br>
  26.   <br>
  27.   <input type="radio" name="q1" value="answer3">Answer3
  28.   <br>
  29.   <br>
  30.   <input type="radio" name="q1" value="answer4">Answer4
  31.   <br>
  32.   <br>
  33.   What  is the answer of second question?
  34.   <br>
  35.   <input type="radio" name="q2" value="answer1">Answer1
  36.   <br> 
  37.   <br>
  38.   <input type="radio" name="q2" value="answer2">Answer2
  39.   <br>
  40.   <br>
  41.   <input type="radio" name="q2" value="answer3">Answer3
  42.   <br>
  43.   <br>
  44.   <input type="radio" name="q2" value="answer4">Answer4
  45.   <input type="submit" value="   submit  " >
  46.  
  47.   </form>
  48.  
  49.  </body>
  50. </html>
Aug 19 '08 #1
5 1242
Markus
6,050 Expert 4TB
Please use code tags when posting code in the forums - read the posting guidelines to find out about codee tags.

the error says what now? Please give the full error - we're not psychics.
Aug 19 '08 #2
pbmods
5,821 Expert 4TB
rubelpasha, you were asked by a moderator on July 9 to start using CODE tags:

[CODE=php]
PHP code goes here.
[/CODE]

This message serves as your official warning. Continued violation of the site Posting Guidelines will result in account suspension.

If you have any questions or concerns, feel free to contact me anytime.

Thanks for your time.

pbmods
Aug 19 '08 #3
nathj
938 Expert 512MB
Did you try a Google search on $_SERVER['PHP_SELF']?

Check out this article

As for the error if you want help with that specifically then I suggest you post the error message.

I have now spent a few minutes running your code and discovered one problem.
You have:
[PHP]
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

change to
[PHP]
<form method="post" action=<?php echo '"' .$_SERVER['PHP_SELF'] . '"'; ?>>

[/PHP]

This then does what it is supposed to.
Cheers
nathj
Aug 20 '08 #4
Atli
5,058 Expert 4TB
This then does what it is supposed to.
No actually, that wouldn't change a thing.

The server doesn't know, or care, what all the other stuff in the page is, it only looks for
<?php ?> tags and execute that as PHP code, whether that is inside quotes or not.
Aug 20 '08 #5
Atli
5,058 Expert 4TB
Hi all,
I want to learn about server side form validation.I have the following source code. But i dont know the meaning of $_SERVER['PHP_SELF']. When i ran this code it shows an error. The error says multiple choice.
I tried your code on my test server. I worked perfectly fine.

Did you post the right code?
Aug 20 '08 #6

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

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.