I found a registration and login code for php and sql on the internet however when I tried to use it , it wouldn't work. Should I just post the entire scipts here?
thanks for any help.
I found a registration and login code for php and sql on the internet however when I tried to use it , it wouldn't work. Should I just post the entire scipts here?
thanks for any help.
Post a link to the code that you found. And tell us what errors you're getting.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
http://www.astahost.com/info.php/php...ipt_t2659.html
This is where I found the code. I'm not even sure if I configered it right so here's the code I copied
This is the registerUser.php file
and this is the page login.phpPHP Code:<?php
if ($_GET['register'] == 'true') {
registerUser();
}
function registerUser() {
mysql_connect('server', 'username', 'password', 'database');
$username = $_POST['username'];
$password = md5($_POST['password']);
$sql = "INSERT INTO tblUsers (fldUsername, fldPassword) VALUES ($username, $password);";
mysql_query($sql);
}
?>
<html>
<head>
<title>Registration</title>
</head>
<body>
<form action="<?php $_SERVER['PHP_SELF']."?register=true" ?>" method="post">
Username: <input type="text" name="username">
Password: <input type="password" name="password">
<input type="submit" value="Register">
</form>
</body>
</html>
When I try to test making an account I click the submit button but nothing happens. Note- I did make the sql database.PHP Code:<?php
if ($_GET['login'] = true) {
loginUser();
} else {
?>
<html>
<head>
<title>Login</title>
</head>
<body>
<form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
Username: <input type="text" name="username"><br>
Password: <input type="password" name="password"><br>
<input type="submit" value="Login">
</form>
</body>
</html>
?>
}
<?php
function loginUser() {
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
$sql = "SELECT fldId, fldPassword FROM tblUsers WHERE fldUsername = '$username';";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if (md5($password) = $row['fldPassword']) {
$_SESSION['loggedin'] = true;
echo "Logged In";
}
}
?>
Thanks for any help
Last edited by jscheuer1; 06-17-2011 at 01:53 PM. Reason: format code
You're not actually connecting the the database
The info for the connect needs to be changed to the login credentials for your database. The script simply provides your what needs to go in the connect but you need to change it to your needs.PHP Code:mysql_connect('server', 'username', 'password', 'database');
This is the code used to make the sql database
CREATE TABLE tblUsers (
fldId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
fldUsername VARCHAR(40) NOT NULL,
fldPassword VARCHAR(40) NOT NULL
);
Is that what you're saying? I'm still really confused. Thanks for any help.
No, you need to change the server, username, password, database to what your login credentials are for your database.
How do I do that?
How do you log in to your database now? Are you on localhost or paid hosting? Either way the username, password and such is the info you need to replace what I told you. If you don't have a database setup yet then you have a lot more work to do than what I told you.
I am using helio host which has php enabled and sql. I just followed the instructions on the page and used that code up the top of this thred in phpmyadmin to make a database. Is this what you're saying. Also, I don't know what I have to change in the code that you pointed out. I'm very new to this so can you please try to explain it to me simply. Thanks for any help.
I am not sure how many different ways you want me to tell you the same thing. I have showed you and told you which items to change 3 times now.
When you setup your database you would have had to create a username and password for the database, use that info in place of the word username and password in the connect line I showed you.
Maybe your username is transformers and the password is optimusprime, I don't know, only you do. Then change the word database in the connect line to what ever you named the database. As for the word server, that is slightly trickier and you may want to contact you host to get that info since you are having such a hard time figuring this out.
Bookmarks