Jump to content

[PHP, HTML] select box problem


r1nk
Go to solution Solved by fastsol,

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

Link to comment
Share on other sites

  • Solution

The comma in this snippet from the query needs to be replaced with AND

username='$username', pass='$password'

Add this line after the query run during production but remove it once the site is working

echo  mysql_error();
Edited by fastsol
Link to comment
Share on other sites

Thanx.. i changed to "AND" and it works..  But i dun use the 2nd command.. Mine explaining me what its function for?

 

And one more thing, how to make the select box option to the right side, below the password form ?

Link to comment
Share on other sites

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>
Edited by fastsol
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.