Jump to content

Archived

This topic is now archived and is closed to further replies.

Chris Val Kef

PHP form handling problem

Recommended Posts

I got a form to select the level of user to login in the system. Part of this code is:

<td height=10><select name="user">
<option value=0 selected> Student</option>
<option value=1> Tutor </option>
</select>
</td>

In php file i use if-else to check the type of user trying to login in order to do the right mysql_db_query in students or tutors table.

Part of code is:

if ( '".$_POST["user"]."' == 1 ) --> for tutors
{
.......
}
else if ( '".$_POST["user"]."' == 0 ) -->for students
{
......
}

The problem is that php checks only if user is student, whether i select in the form tutor or student.
If the user and password are correct it returns the student pages, whether i selected tutor or student.
It's just looking in the student table.

I've tried some things and when in the IF-ELSE i changed 0 and 1 for student and tutor
i noticed that php then looks only in tutors table.

I think i'm doing something wrong with the <SELECT name=...>, <OPTION value=...> and IF-ELSE...

Got any ideas???

Thank you all in advance!

Share this post


Link to post
Share on other sites
Your if/elseif statment is a little wrong it should be this:
[code]if ($_POST['user'] == 1 )
{

}
else if ($_POST['user'] == "student" )
{

}[/code]
What is the code you use for your [i]<SELECT name=...>, <OPTION value=...>[/i]? It show be something like this:
[code]<select name="user">
  <option value="student">Student</option>
  <option value="tutor">Tutor</option>
</select>[/code]Then your if/elseif statment should look like this:
[code]if ($_POST['user'] == "student" )
{
    //code for student
}
else if ($_POST['user'] == "tutor" )
{
   //code for tutor
}[/code]

Share this post


Link to post
Share on other sites
THANK YOU!!!

It finally works...

I've tried before what you told me but my mistake was in the if-else statements.

I was using '".$_POST["..."]."'.... I am a newbie...

THANX again!

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.