Post here is you are having problems with any of the tutorials.
Owinzin
Posts: 5 Joined: Sun Mar 04, 2012 7:07 pm
Post
by Owinzin » Sun Mar 04, 2012 7:10 pm
Well so I am getting this error upon submitting my form:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\devshare\core\func\user.func.php on line 35
And this is the code it isn't liking:
function userExists($username) {
$username = mysql_real_escape_string($username);
$total = mysql_query("SELECT COUNT('id') FROM users WHERE username =$username");
return (mysql_result($total, 0) == '1') ? true : false;
}
Please help, thank you.
Temor
Posts: 1186 Joined: Thu May 05, 2011 8:04 pm
Post
by Temor » Sun Mar 04, 2012 7:25 pm
your using single-quotation marks ( ' ) where you should be using backticks ( ` )
if you add
echo mysql_error();
under the query that is failing it will tell you what's wrong.
Owinzin
Posts: 5 Joined: Sun Mar 04, 2012 7:07 pm
Post
by Owinzin » Sun Mar 04, 2012 8:45 pm
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 '' at line 1
I changed it to backticks.
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Mon Mar 05, 2012 10:44 pm
You also want quotes around $username at the end of the SQL.
Owinzin
Posts: 5 Joined: Sun Mar 04, 2012 7:07 pm
Post
by Owinzin » Wed Mar 07, 2012 5:22 pm
I don't see why I do? I have used a variable in MYSQL without quotes and it has worked fine. But I will try anyway.
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Thu Mar 08, 2012 1:15 am
Owinzin wrote: I don't see why I do? I have used a variable in MYSQL without quotes and it has worked fine. But I will try anyway.
It's not to do with the fact that it's a variable.
When you put a variable in a string like that it just replaced it with the variables value. If you variable contains a sting it needs quotes or mysql will not know what to do with it.
Owinzin
Posts: 5 Joined: Sun Mar 04, 2012 7:07 pm
Post
by Owinzin » Sun Mar 11, 2012 7:04 pm
Now it won't send to the database.
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Mon Mar 12, 2012 8:14 pm
Owinzin wrote: Now it won't send to the database.
Post your code.
Owinzin
Posts: 5 Joined: Sun Mar 04, 2012 7:07 pm
Post
by Owinzin » Wed Mar 14, 2012 4:23 pm
function userRegister($username, $password){
$username = mysql_real_escape_string(htmlentities($username));
$password = sha1($password);
mysql_query("INSERT INTO users (username, password) VALUES ($username, $password)");
}
Temor
Posts: 1186 Joined: Thu May 05, 2011 8:04 pm
Post
by Temor » Wed Mar 14, 2012 4:49 pm
you need single quotation marks around your variables, and also backticks around your column names.
function userRegister($username, $password){
$username = mysql_real_escape_string(htmlentities($username));
$password = sha1($password);
mysql_query("INSERT INTO users (`username`, `password`) VALUES ('$username', '$password')");
}