I have two problems.
problem one:
I am trying to create a registeration form where users can register with my website.
when I run this mysql statement a get dublicate entry found error:
$sql "insert into users(username, password) values('$username, sha('$password'))";
Duplicate entry ‘da39a3ee5e6b4b0d3255bfef95601890afd80709’ for key ‘password’
despite the fact that I changed the the string sha(‘$password’) several times.
please help.
else{
include("databaseconnection.php");
$databaseconnect = connect($host,$user,$password,$database)
or die("couldnot connect to database serever.\n");
$database_select = mysql_select_db($database,$databaseconnect)
or die("could not select dabases.\n " .mysql_error());
$query2 = "insert into company(username,password)
values('$username',sha1('$password'))";
$result2 = mysql_query($query2,$databaseconnect);
echo "you have been registered as '$companyloginName' <br/>";
header("Location:/index.php");
my login php script is as follow:
$result ="select username, password form users where username ='$username' and password = sha('$password');
if(mysql_num_rows($reuslt)==1){
echo"welcome '$username";
}
da39a3ee5e6b4b0d3255bfef95601890afd80709is the sha1 hash of the empty string. Make sure that you actually insert the password into your SQL query, for example by echoing the query instead of sending it to the SQL server.Edit With the new information added to your question, check out these two lines:
Here,
$passwordis the password used to connect to the database. The inclusion of databaseconnection.php probably overwrites what was previously in the$passwordvariable.Try to
echo $query2and you’ll probably see it for yourself, that the SQL query doesn’t include any password at all or that the password therein is not the same as the one entered by the user.