Jump to content

first php login help plz


littlething

Recommended Posts

MySQL version: 5.0.51b

PHP version    :5.2.6

 

ok i have just started prgraming my first text based php game. i have connected to the database using this code

 

$user = "root";

$host = "localhost";

$password = "";

$database = "game";

$cxn = mysql_connect($host,$user,$password,$database)

or die ("Coundn't connect to the database server.");

 

and that works fine. then i got this bit that i am using to call up the users password and because i am in development

stages i just added a test username.

 

$query = "SELECT password FROM members WHERE username = 'littlething'";

$result = mysql_query($query,$cxn)

or die ("Couldn't execute login query.");

 

i have cheaked the sql to see if it works in phpmyadmin and it comes up with the password from the members table

but when its in this code it just dies "Couldn't execute login query." . i have tryed loads of different variations such as

mysqli_query and mixin about query and cxn but they all come up with error messages like

 

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\index.php on line 34

 

i am absolutly sure all my tables, databases, colums and cap letters are fine in the mysql database. what i would like it

to do is give an output of the password to the $result var.

 

plz could sombody tell me where i have gone wrong?

Link to comment
Share on other sites

mysql_connect only takes 3 of those parameters, you pass the DB connect on a different line.

 

$user = "root";

$host = "localhost";

$password = "";

$database = "game";

$cxn = mysql_connect($host,$user,$password) or die ("Couldn't connect to the database server.");

 

$result = mysql_select_db ($database) or die ("Couldn't connect to the database.");

 

Link to comment
Share on other sites

ok now i have got

 

$user = "root";

$host = "localhost";

$password = "";

$database = "game";

$cxn = mysql_connect($host,$user,$password) or die ("Couldn't connect to the database server.");

 

$result = mysql_select_db ($database) or die ("Couldn't connect to the database.");

 

for the connection and

 

$query = "SELECT password FROM members WHERE username = 'littlething'";

$result = mysql_query($query)

or die ("Couldn't execute login query.");

 

for my query but the output of the $result when i echo it is

 

Resource id #3

 

i have also tryed th query

 

$query = "SELECT * FROM members WHERE username = 'littlething' AND password = 'mypass'";

 

but that reterns the same thing??? how would i fix that?

 

and 1 athoer small question what code would say if there was an answer to the query i sent?

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.