Jump to content


Photo

PHP form handling problem


  • Please log in to reply
2 replies to this topic

#1 Chris Val Kef

Chris Val Kef
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 10 April 2006 - 10:39 AM

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!

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 10 April 2006 - 10:51 AM

Your if/elseif statment is a little wrong it should be this:
if ($_POST['user'] == 1 ) 
{

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

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


#3 Chris Val Kef

Chris Val Kef
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 10 April 2006 - 08:10 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users