problem with login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dertysweet
Forum Newbie
Posts: 4
Joined: Thu Jul 08, 2010 8:10 am

problem with login

Post by dertysweet »

hello......

i have a site on a free php, mysql host and i can't seem to make login to work.
i have a db created and a table called admin with one user(1, admin, pass)

when i use:

Code: Select all

[color=#BF0040]<?php
ob_start();
include("ofnibd.php");


mysql_connect("$hostname", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$database")or die("cannot select DB");


$user=$_POST['admin']; 
$parola=$_POST['password']; 

$sql="SELECT * FROM admin WHERE user='admin' and parola='pass'";
$result=mysql_query($sql);


$count=mysql_num_rows($result);


if($count==1){

session_register("user");
session_register("parola"); 
header("location:update_oferta.php");
}
else {
header("location:main_login.php?eroare=eroare");
}
?>[/color]
it work but it bypasses login form by always connecting with the user in table "admin"


but when i use

Code: Select all

[color=#FF0000]<?php
ob_start();
include("ofnibd.php");


mysql_connect("$hostname", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$database")or die("cannot select DB");


$user=$_POST['admin']; 
$parola=$_POST['password']; 

$sql="SELECT * FROM admin WHERE user='$user' and parola='$parola'";
$result=mysql_query($sql);


$count=mysql_num_rows($result);


if($count==1){

session_register("user");
session_register("parola"); 
header("location:update_oferta.php");
}
else {
header("location:main_login.php?eroare=eroare");
}
?>
[/color]
it always says wrong username or password! what am i doing wrong? could it be because of the free host?
Skiddles2010
Forum Newbie
Posts: 19
Joined: Tue Jul 06, 2010 11:05 pm

Re: problem with login

Post by Skiddles2010 »

Well, in your first block of code, that one works because it's not utilizing the $_POST variables. Instead you're directly inputting "admin" and "pass", which is in the db table, so it's validated. In the second block of code, the only thing that changes is that you are now actually using the user's input from a form. I'd suspect the error might be in the form.html (or wherever this data is being POST'd from). Perhaps your form is set to $_GET? Post your code for the form and we can take a look.

PS: For debugging, you might want to also try throwing in an echo on the login error bit to show what was recieved as an inputted username and password. That should help isolate the problem.
dertysweet
Forum Newbie
Posts: 4
Joined: Thu Jul 08, 2010 8:10 am

Re: problem with login

Post by dertysweet »

Code: Select all

<?
$eroare=$_GET['eroare'];
if($eroare == 'eroare'){echo '<p align="center"><strong><font color="#FF0000">Wrong username or password!</font></strong></p>';}
?>

tell me......what do i need to replace?
Skiddles2010
Forum Newbie
Posts: 19
Joined: Tue Jul 06, 2010 11:05 pm

Re: problem with login

Post by Skiddles2010 »

Post the code to the actual form that the user fills out i.e. <form>...</form>
Last edited by Skiddles2010 on Thu Jul 08, 2010 9:56 am, edited 1 time in total.
dertysweet
Forum Newbie
Posts: 4
Joined: Thu Jul 08, 2010 8:10 am

Re: problem with login

Post by dertysweet »

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#F4E5BC">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#F4E5BC">
<tr>
<td colspan="3"><strong>Admin Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="user" type="text" id="user"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="parola" type="password" id="parola"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>
Skiddles2010
Forum Newbie
Posts: 19
Joined: Tue Jul 06, 2010 11:05 pm

Re: problem with login

Post by Skiddles2010 »

Change this...

Code: Select all

$user=$_POST['admin'];
$parola=$_POST['password']; 
to this...

Code: Select all

$user=$_POST['user'];
$parola=$_POST['parola']; 
and you should be fine. Notice the input names you have chosen in your form need to match up with the $_POST definitions in your checklogin.php.
dertysweet
Forum Newbie
Posts: 4
Joined: Thu Jul 08, 2010 8:10 am

Re: problem with login

Post by dertysweet »

OMG 10x MAN

it worked.

i also have a problem with photo upload in an add. it doesn't upload them. "problem in creating image"\

could u please give me a PM with ur yahoo id to chat more easily?
Skiddles2010
Forum Newbie
Posts: 19
Joined: Tue Jul 06, 2010 11:05 pm

Re: problem with login

Post by Skiddles2010 »

i also have a problem with photo upload in an add. it doesn't upload them. "problem in creating image"\

could u please give me a PM with ur yahoo id to chat more easily?
Well, I can't because I'm at work. Plus I don't know a whole lot about scripting image uploads. But I'm sure if you post the code/problem in detail, some of the pros here could be of assistance. I'd recommend creating a new topic for that particular problem.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: problem with login

Post by Jade »

Post Reply