Jump to content

[PHP, HTML] select box problem


r1nk

Recommended Posts

Hey, i got another question. Ok so far i have a table called users (id, name, username, pass, type) and here is my coding so far..

<html>
	<head>
		<title> Login Form </title>
	</head>

<body>
<form method='post' action='login.php'>
	<table width='400' border='5' align='center'>
	<tr>
		<td align='center'
		colspan='5'><h1>Login Form</h1></td>
	</tr>
	
	<tr>
		<td align='center'>Username:</td>
		<td><input type='text' name='username' /></td>
	</tr>
	
	<tr>
		<td align='center'>Password:</td>
		<td><input type='password' name='pass' /></td>
	</tr>
	
	
	<tr>
	<td align='center'>
	<select name="type" id="type">
	<option value="0 selected="selected">Select user type</option>
	<option value="admin">Admin</option>
	<option value="student">Student</option>
	</select>
	</tr>
	
	<tr>
		<td colspan='5' align='center'><input type='submit' name='login' value='Log In' /></td>
	</tr>
	
	</table>
</form>
</body>
</html>
<?php
mysql_connect("localhost","root","");
mysql_select_db("student_attendance");

if(isset($_POST['login'])){

	$username = $_POST['username'];
	$password = $_POST['pass'];
	$type = $_POST['type'];
	
	$check_user = "select * from users where username='$username', pass='$password' AND type='$type'";
	
	$run = mysql_query($check_user);
	
	if(mysql_num_rows($run)>0){
	
	echo
	"<script>alert('You are logged in')</script>";
	}
	else {
	echo "<script>alert('username,password or user type is incorrect!')</script>";
	}
}

?>

And when i viewed it looks like this.. http://i272.photobucket.com/albums/jj178/r1nk_2008/prob_zpsd907ed84.png

 

So my questions are :-

 

-how to make the select box option to the right side, below the password form ?

-how to fix the error so that when i enter correct username, pass and type it says "you are login" ?

Link to comment
https://forums.phpfreaks.com/topic/281674-php-html-select-box-problem/
Share on other sites

Looks like most of the issue is with this block

<tr>
	<td align='center'>
	<select name="type" id="type">
	<option value="0 selected="selected">Select user type</option>
	<option value="admin">Admin</option>
	<option value="student">Student</option>
	</select>
	</tr>

You're missing a clising </td> after the </select> and a closing " for the 1st option value.

The mysql_error() will display the reason the query failed.

To place the select box you need to add an empty td in the table

<tr>
       <td></td> // This is the empty cell
	<td align='center'>
	<select name="type" id="type">
	<option value="0 selected="selected">Select user type</option>
	<option value="admin">Admin</option>
	<option value="student">Student</option>
	</select></td>
	</tr>

Archived

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

×
×
  • 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.