Solved

condition on submit

Posted on 2002-07-02
13
288 Views
Last Modified: 2012-05-04
if i want to make a condition on clicking on submit button in a form, how can i do it in php?
for example if i have a page where the user have to login using his username and password saved already in a database (MySQL), i want to realize the condition that its username and password are just right like in the database. I have tried the condition if ($submit) but it didn't worked (i don't know why because i have seen some tutorials using this condition).
I am working on PHP version 4.2.1 and MySQL.

How can I do it?
Is this version of PHP different?
0
Comment
Question by:htannoury
  • 6
  • 4
13 Comments
 
LVL 6

Expert Comment

by:andreif
ID: 7124086
if you want to use $submit variable, you should ensure that submit control's name us "submit":

<input type="submit" name="submit" value=" Click! ">
0
 

Author Comment

by:htannoury
ID: 7124101
i have tried this but it didn't worked
0
 
LVL 6

Expert Comment

by:andreif
ID: 7124111
in this case problem can be in "Register Globals" switched off mode. In this case $submit variable is not defined.

For PHP 4.2+ use
$_GET["submit"] or $_POST["submit"] (depends on form method)
variables

0
 
LVL 6

Expert Comment

by:andreif
ID: 7124115
more information about predefined variables

http://www.php.net/manual/en/language.variables.predefined.php
0
 

Author Comment

by:htannoury
ID: 7124300
In the form (method="post") that i use i have written the submit input like this:
<input type="submit" name="submit" value="click">
in the form i have a field of name "first"

and the condition is written here:
<?
$submit=$_POST['submit'];
echo "<br>";

echo "submit is $submit";
echo "<br>";
 
if($submit == "click")
     {
     if ($first == "")
          {echo "you have to type your first name";}
          else
          {echo " thank you for your first name";
               }
     }
     else
     {
     echo "you have to click on submit";
     }
?>

i always obtained the notice: undefined index submit.
do you expect that there is something missing in the configuration of the php? what i have to do?

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:andreif
ID: 7124306
try to print out $_POST array in the beginning of the script

print_r($_POST);
0
 

Author Comment

by:htannoury
ID: 7124349
I have used $_POST in the second file (action of the form)
and i used the condition that i have written so it worked. Thank you about your cooperation, but is there a way to let this condition work in the same file?
0
 
LVL 6

Expert Comment

by:andreif
ID: 7124371
In this case condition should be more complex.

What does your script do with the form data?
Does it checks username/password in database?
0
 

Author Comment

by:htannoury
ID: 7124462
Yes it is for checking the username and password.
Is it necessary to have a new page where the condition should be written?
0
 
LVL 6

Accepted Solution

by:
andreif earned 50 total points
ID: 7124471
You can us the same page, but form action should be directed to the page itself, not to another one
0
 
LVL 11

Expert Comment

by:shmert
ID: 9643672
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept: andreif
Please leave any comments here within the next seven days.
               
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
               
Sam Barnum
EE Cleanup Volunteer              
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now