/    Sign up×
Community /Pin to ProfileBookmark

help me with signup and login script

this is my sign up script…

[code=php]
<?php

$fname = $_POST[‘fname’];
$lname = $_POST[‘lname’];
$gender = $_POST[‘gender’];
$email = $_POST[’email’];
$password1 = $_POST[‘pass1’];
$password2 = $_POST[‘pass2’];

if($password1 != $password2)
header(‘Location: signup.html’);

$passwordHash = sha1($_POST[‘pass1’]);

$mysqli = new mysqli(‘localhost’, ‘root’, ‘dhiraj’, ‘test’); //we change the mysqli_connect to “new mysqli”

$query = “INSERT INTO users ( u_fname, u_lname, gender,u_email, u_pass) VALUES
( ‘$fname’, ‘$lname’, ‘$gender’ , ‘$email’, ‘$passwordHash’ )”;

//remove $conn variable in order to connect to our database using OOP.
$mysqli->query($query);

$mysqli->close();

header(‘Location: index.html’);
?>
[/code]

and this is login script

[code=php]
<?php
$email = $_POST[‘log_email’];
$passwordHash = sha1($_POST[‘log_pass’]);

$conn = mysqli_connect(‘localhost’, ‘root’, ‘dhiraj’, ‘test’);

$query = “SELECT u_fname
FROM users
WHERE u_email = ‘$email’ AND u_pass=’$passwordHash’;”;

$result = mysqli_query($conn, $query);

if(mysqli_num_rows($result) < 1)
{
echo ‘Sorry, your username or password was incorrect!’;
// this echo statement gets executed. what is the problem?
}

else
{
/* Log user in */
echo “Welcome back $_POST[‘log_email’] “;
}
?>
[/code]

So everything works …has is calculated on password…database gets updated bu the problem is after login
the echo statement gets executed ..means no result generated from the query in the login script.
pls help me.

would love if provide any script. Thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmAug 22.2013 — If you had written proper code that checked for errors you would have seen an sql error in your query. You have an extra semi in your query.
Copy linkTweet thisAlerts:
@rootAug 23.2013 — Your script security is very poor, your script is open to attack.

You need to check if the script the $_POST['submit'] is present when executed and also have a function to sanitize the inputs in to an array.

You will find plenty of examples already posted on this site.
×

Success!

Help @dhirajkumar_41 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...