Jump to content

PHP form handling problem


Chris Val Kef

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!
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.