Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

PHP-MYSQL Help

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Souleclipse

Established Member
Impact
0
Hi, i need help with my PHP

My login form is :
<form action = 'login.php' method='POST'>

<input type="text" name="username" onfocus="if(this.value=='Username'){this.value=''};" onblur="if(this.value=='')
{this.value='Username'};" value="Username" /> <br />

<br />

<input type="password" name="password" onfocus="if(this.value=='Password'){this.value=''};" onblur="if(this.value=='')
{this.value='Password'};" value="Password" /> <br />

<input type="submit" value="Login" /> <br />
<br />
</form>


My login.php is :
<?php
session_start();
include_once("header.php");
SESSION['name'];
echo $_SESSION['name'];

require_once("opendb.php");

$name=$_POST['username'];
$password=$_POST['password'];
$passwords=sha1($password);

$query = "SELECT * FROM users WHERE Name = '".$name."' AND Password = '".$passwords."'" ;

// execute query

$result = mysql_query($query) or die (mysql_error());

if(mysql_num_rows($result) == 1) {
$_SESSION['name'] = $_POST['username'];
echo "welcome";
}
else {
echo "Login fail. Please login again";
}

include_once("footer.php");
?>

It keep display login fail. Anyone know why? dbs seem correct.
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
First of all, you are getting syntax errors because

PHP:
SESSION['name'];

is not a valid line of code.

Put a LIMIT 1 at the end of your query just in case there are two users with the same username/password (which should never happen anyway...).

Your best bet here is to do some echo statements and just print all the information you can. How many rows is it returning? I bet it's 0. Do an echo to confirm this.
 
0
Close
i done an echo , but none came out. i can do a register with the same db connection.
the session['name'] i comment it alr =(
 
0
Close
If nothing was displayed then the number of rows returned is 0.

This means your query isn't getting any results.

This means something ISN'T, in fact, right with your database, the way you intend it to be, anyway. "Db seems correct" is faulty. Double-check your database.
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Member card: see how many threads a member started
The member card now shows a Threads number, right after Posts. The member card is the box that opens when you point at a name. Profile...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back