Jump to content

SQL Problems


Drezard

Recommended Posts

Okay heres my code:

 


$query = "SELECT * FROM user_chars WHERE user='$user' AND `character`='1'";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

$count = mysql_num_rows($result);

 

Now in my Database under character it is 1. The only problem is when i run this script, count = 0.

 

The variable $user contains the right stuff what else could it be?

 

- Cheers, Daniel

Link to comment
https://forums.phpfreaks.com/topic/37880-sql-problems/
Share on other sites

if the character is a number and not text then remove the single ticks from around the 1

 

<?php

$query = "SELECT * FROM user_chars WHERE user='$user' AND `character`=1";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

$count = mysql_num_rows($result);

?>

 

try that.

Link to comment
https://forums.phpfreaks.com/topic/37880-sql-problems/#findComment-181352
Share on other sites

You use ` when the word is a reserved word, such as a field called order. It is a bad idea to have your fields named that way, so you shouldn't generally need to use them. character is a reserved word:

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

 

You use ' to surround a string. It shouldn't hurt to put single quotes around numbers, as you might get unexpected content, so it can help stop errors.

Link to comment
https://forums.phpfreaks.com/topic/37880-sql-problems/#findComment-181593
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.