PHP Login Servers

toontow7

New Member
Messages
16
Reaction score
0
Points
1
I Created a DataBase, and ik my code works perfectly, since i used xampp to test.
The code seems fine, it just seems that its not accepting my username and password.

What format are the PHPmyAdmin Username and Passwords?
Are they your toontown email and password?

and i set the server to localhost, which it seems to say.
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
Actually, it works now, but it dosnt seem my PHP server is working.
The username and password row i created is not working.
it registers the database, but dosnt register information.
IK this code works.
 

Dead-i

x10Hosting Support Ninja
Community Support
Messages
6,084
Reaction score
367
Points
83
Hi toontow7,

The database details your script is incorrect, as the database user you have specified does not exist. Please create a new database user in cPanel, and then use that one in login.php.

Thank you,
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
cPanel regular ...
Databases section
MySQLDatabases <----- click on
Middle of page. "Add New user"
If your cPanel username is "george" and you add "bush", the full username will be "george_bush"
Write down the password
Then, after you have created the user, "Add User To Database" ... add it to your database WITH ALL PRIVILEGES.
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
I created one, but i got this:
[02-Oct-2014 18:43:04 America/New_York] PHP Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/toontow7/public_html/mysql_login/login.php on line 19
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
1) Do not use mysql_xxxxx functions. Use mysqli_xxxxx or PDO. mysql_ is old, deprecated, and soon will not run at all on PHP versions.

2) You are running mysql_num_rows( $result ) and $result is FALSE --- ie your original query FAILED.

3) You can always use cPanel --> phpMyAdmin to look into your database and check the actual values in your tables.
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
Well, first when i do mysqli_xxxx, it gives me a bunch of errors, saying i need more parameters.
Second of all, if i do mysql_xxx, It gives me that one error.
The query dosnt seem to have anything wrong with it:
$query = "SELECT * FROM `users` WHERE `Username`='$myusername' and `Password`='$mypassword' ";
http://gyazo.com/8ed4b2b3adabf5aaeaa824f43526a50c
 

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Moved to Scripts and 3rd Party Apps
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Second of all, if i do mysql_xxx, It gives me that one error.
The query dosnt seem to have anything wrong with it:
$query = "SELECT * FROM `users` WHERE `Username`='$myusername' and `Password`='$mypassword' ";

Well, your query returns a BOOLEAN -- see the error message you get when you try to use the result in another function.
It only returns a boolean when you have an ERROR.
So, something is wrong.
Every database driver has a function to recover the last error.
mysql_xxxxx has mysql_error() .
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
So, i still havent solved the problem. I dont know whats wrong....
dosnt seem like anything's wrong. It works on the my localhost xampp phpmyadmin.
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
Did you print out the results of mysql_error() ? Did you?

Print out $query to make sure it looks right. Print it from the script. Running on x10hosting, not your local machine.

Try removing the quotes from around users , Username and Password.

The fact that it runs on your local machine means very little.
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
I get this when I do die(mysql_error());
"No database selected"
same as if I remove the ` ` from the query.

EDIT

I added a USE $hostname
to my query,
i got this:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'SELECT * FROM users WHERE Username='admin' and Password='thunder'' at line 1
 

toontow7

New Member
Messages
16
Reaction score
0
Points
1
<?php

$username = "myusername";
$password = "mypassword";
$hostname = "localhost";

$databasehandle = mysql_connect($hostname, $username, $password) or die("Couldn't Connect to the database!");

$selected = mysql_select_db("login", $databasehandle);

$myusername = $_POST['user'];
$mypassword = $_POST['pass'];

$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$query = "USE `localhost` SELECT * FROM `users` WHERE `Username`='$myusername' and `Password`='$mypassword'; ";
$result = mysql_query($query);
$count = mysql_num_rows($result);

if($count == 1) {
$seconds = 300 + time();
header("location:login_success.php");
setcookie(loggedin, date("F jS - g:i a"), $seconds);
} else {
die(mysql_error());
}

mysql_close();

?>
 

AngusThermopyle

Active Member
Messages
319
Reaction score
52
Points
28
$selected = mysql_select_db("login", $databasehandle);

The database name would be of the form: yourcPanelUsername_login
You can test $selected ... FALSE means failure, TRUE means success.
 
Top