bravo14 Posted September 14, 2008 Share Posted September 14, 2008 Hi guys I have included a part of the code I am trying to use, I am basically trying to see if a username is already in use before adding the record to the database. <?php include ("includes/connector.php"); //*assign names to variables $username = $_POST[username]; $first_name = $_POST[firstname]; $surname = $_POST[surname]; $email = $_POST[email]; $password = $_POST[password]; $address1 = $_POST[address1]; $address2 = $_POST[address2]; $address3 = $_POST[address3]; $address4 = $_POST[address4]; $postcode = $_POST[postcode]; //*check if username already exists $cxn = mysql_connect($host, $user, $passwd, $dbname) or die ("Couldn't connect to server"); $sql = "SELECT username FROM customers WHERE username = '$username'"; $result = mysql_query($cxn,$sql) or die ("Query died: user name"); //line 145 $num = mysql_num_rows($result); The error message I am getting is Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\alhassam\register.php on line 145, I have indicated line 145 above, can anyone point out my error. Cheers Quote Link to comment https://forums.phpfreaks.com/topic/124157-mysql-query-error/ Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 Your parameters are round the wrong for mysql_query. Line 145 should be $result = mysql_query($sql, $cxn) or die ("Query died: user name"); Quote Link to comment https://forums.phpfreaks.com/topic/124157-mysql-query-error/#findComment-641000 Share on other sites More sharing options...
bravo14 Posted September 14, 2008 Author Share Posted September 14, 2008 Thanks for that, have made the correction but now I am getting the die error and again can't see anything wrong with the query or execution of it $cxn = mysql_connect($host, $user, $passwd, $dbname) or die ("Couldn't connect to server"); $sql = "SELECT username FROM customers WHERE username = '$username'"; $result = mysql_query($cxn,$sql) or die ("Query died: user name"); //line 145 Quote Link to comment https://forums.phpfreaks.com/topic/124157-mysql-query-error/#findComment-641154 Share on other sites More sharing options...
wildteen88 Posted September 14, 2008 Share Posted September 14, 2008 Add mysql_error() in your die statement $result = mysql_query($sql, $cxn) or die ("Query died: ". mysql_error()); //line 145 Quote Link to comment https://forums.phpfreaks.com/topic/124157-mysql-query-error/#findComment-641155 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.