tom232 Posted January 3, 2007 Share Posted January 3, 2007 Im getting this error: ???[i]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Resource id #10' at line 1[/i]what does this mean and how do i fix?[code]<?phprequire_once('db_fns.php');function register($username, $email, $password)// register new person with db// return true or error message{ // connect to db $conn = mysql_connect(localhost, collegenote, ++++++); // check if username is unique $q = "select username from users where username = '$username'"; $result = mysql_query(" $q, $conn"); IF (!$result) THROW NEW EXCEPTION(mysql_error($conn)); if ($result->num_rows>0) throw new Exception('That username is taken - go back and choose another one.');[/code] Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/ Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 [code=php:0]$result = mysql_query($q, $conn);[/code]You also need to fix this...[code=php:0]$conn = mysql_connect("localhost", "collegenote", "++++++");[/code]And dont post your password on the board, can cause all sorts of issues. Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152218 Share on other sites More sharing options...
tom232 Posted January 3, 2007 Author Share Posted January 3, 2007 you need the quotations around it for the script to reconginze the server Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152219 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 Variables do NOT need to be surrounded with quotes. Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152220 Share on other sites More sharing options...
tom232 Posted January 3, 2007 Author Share Posted January 3, 2007 well it gives me the error: database has not been selected Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152221 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 Because you have no call to [url=http://php.net/mysql_select_db]mysql_select_db[/url]. Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152222 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 Your next error is going to be this....[code=php:0]if ($result->num_rows>0)[/code]Should be....[code=php:0]if (mysql_num_rows($result) > 0)[/code] Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152223 Share on other sites More sharing options...
tom232 Posted January 3, 2007 Author Share Posted January 3, 2007 how do i use the mysql_select_db;[i]$result = mysql_select_db($q, $conn);[/i] ??thanks Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152227 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 Did you look at the manual entry I provided a link to?[code=php:0]$conn = mysql_connect("localhost", "collegenote", "++++++");mysql_select_db("yourdatabasename");[/code] Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152231 Share on other sites More sharing options...
tom232 Posted January 3, 2007 Author Share Posted January 3, 2007 oo ok thanks alot! Link to comment https://forums.phpfreaks.com/topic/32708-solved-sql-problems/#findComment-152237 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.