littlething Posted August 4, 2008 Share Posted August 4, 2008 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? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted August 4, 2008 Share Posted August 4, 2008 your doing a mysql query connect, and mysqli query, you have to choose one or the other not both. and you have a poor query string. $query = "SELECT * FROM members WHERE username = 'littlething' AND password = 'mypass'"; Quote Link to comment Share on other sites More sharing options...
littlething Posted August 4, 2008 Author Share Posted August 4, 2008 sry i am not to good at this query thing how would i do a mysql query? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 5, 2008 Share Posted August 5, 2008 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."); Quote Link to comment Share on other sites More sharing options...
littlething Posted August 5, 2008 Author Share Posted August 5, 2008 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? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 6, 2008 Share Posted August 6, 2008 There is nothing to fix, a Resource ID is the proper return. What you need to do is use a mysql_fetch function to get the data from that Resource ID. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.