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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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