-
I'd definitely say to contact you host for this info. For example, if phpmyadmin was already set up when you opened your hosting account, you might have never known these details.
Your username and password are probably (but maybe not) the same as those you use to log in to phpmyadmin. The database name should be shown in your phpmyadmin panel. As for "server," different hosts have different ways of configuring them and different ways of allowing access from your sites.
Once you have determined your database credentials, use them in place of the "server, username, password, database" in your code. However, for security reasons, always ********* them when you post your code here (or anywhere online).
On a related subject, mysql_connect() does not accept the database and/or table name as an argument:
PHP Code:
// the fourth argument is (boolean)new_link, not the database name.
// if you put anything there (other than FALSE), it will simply be interpreted as "true"
// it won't throw an error, but it won't do what you expect, either.
mysql_connect('servername','username','password','databasename');
// this will have no result
$r = mysql_query("select * from table");
// and this will return:
// " No database selected. "
print mysql_error();
// leave 'databasename' _out_ of mysql_connect()
// you need to use this after you connect:
mysql_select_db('databasename');
//and then you can continue with your queries
-
Thanks for all your help everybody. I think I finally got the registration bit working. However there is another problem. :( For the page Thats meant to log them in I just get this.
Fatal error: Can't use function return value in write context in /home1/keyboard/public_html/login.php on line 37
The code is
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";
}
}
?>
.
I know I'm not very good at this so thanks for your patience.
-
is this:
PHP Code:
<form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
line 37?
it should be written:
PHP Code:
<form action="<?php print $_SERVER['PHP_SELF']."?login=true"; ?>" method="POST">
-
I'm still getting this error
Fatal error: Can't use function return value in write context in /home1/keyboard/public_html/login.php on line 37
I changed what you said. Any help is appreciated
-
Try this, whoever wrote this didn't reopen the php tag correct after the html form.
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";
}
}
?>
-
Still coming up with the same error. I think I will find a new project to work on.
-
this does seem to be written a little sloppily. before giving up, however, could you let us know which line is line 37? That would certainly help with troubleshooting.
-
Or how about the fact that they forgot the semicolon on this line and the echo
PHP Code:
<form action="<? $_SERVER['PHP_SELF']."?login=true" ?>" method="POST">
Should be this
PHP Code:
<form action="<? echo $_SERVER['PHP_SELF']."?login=true"; ?>" method="POST">
I agree that this is very poorly written. Not even sure how the person got this to work in the first place let alone post it somewhere for others to use. If you want a really good tutorial that uses proper coding practices and security features, check this youtube channel out and look for his login/registration videos - there are a few of them - http://youtube.com/betterphp