SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem in query..I think with spaces?

    Hey guys,

    I have a query I'm using, and I can't figure out what the problem is with it...I am thinking maybe it is the space in the names? I'm not sure...

    Well, the query is:
    PHP Code:
    echo("num=$num , pos=$position , name=$name , teamid=$teamid");
    $sql mysql_query("SELECT * FROM players WHERE name='$name' AND pos='$position' AND num='$num' AND teamid='$teamid'");
    $nums mysql_num_rows($sql);
    if(
    $nums 0) {
    while (
    $row mysql_fetch_array($sql)) {
    // do stuff here

    There is the basic layout of that part of the code, and the echo() I use produces this:

    num=23 , pos=c , name=britt warner , teamid=19
    I dunno how to show the information in a table, other than exporting it, so I will just show you guys the export I did, and it will show you that those details seem to be in the table, unless I'm missing something

    TABLE `players` (
    `ID` int(11) NOT NULL auto_increment,
    `name` varchar(255) default NULL,
    `pos` varchar(255) default NULL,
    `num` int(11) default '0',
    `g` int(11) default '0',
    `ab` int(11) default '0',
    `r` int(11) default '0',
    `h` int(11) default '0',
    `s` int(11) default '0',
    `2b` int(11) default '0',
    `3b` int(11) default '0',
    `hr` int(11) default '0',
    `rbi` int(11) default '0',
    `bb` int(11) default '0',
    `er` int(11) default '0',
    `k` int(11) default '0',
    `slg` decimal(4,3) default '0.000',
    `avg` decimal(4,3) default '0.000',
    `teamid` int(11) default NULL,
    PRIMARY KEY (`ID`)
    ) TYPE=MyISAM AUTO_INCREMENT=24 ;
    INSERT INTO `players` VALUES (19, 'britt warner', 'c', 23, 13, 23, 10, 8, 8, 8, 8, 8, 8, 8, 8, 8, 3.182, 0.318, 19);

    Sorry for such a long post, but I hope I included all the details I needed to, because I'm not too great with mysql
    http://chaseschwalbach.com

  2. #2
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't actually said what your problem is.

    - Does the query not return any rows?
    - Is the query invalid and you get a 'not a valid mysql resource' error?
    - Something else?

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry,

    I get a not a valid mysql resource error

    Thanks
    http://chaseschwalbach.com

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    naperville
    Posts
    189
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try mysql_query(sql..) OR die(mysql_error());

    See if it gives you an error. Also, check it in PHPMyAdmin - this is easier to debug /modify queries

  5. #5
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,

    It doesn't give me an error other than what it had before(on the mysql_fetch_array is where I'm getting the error, not on the query itself) but on phpmyadmin I get:

    #1064 - 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 '"SELECT * FROM players WHERE name='britt warner' AND pos='c' AN
    http://chaseschwalbach.com

  6. #6
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That seems a bit of a bizarre one.

    Humour me and try this...

    Code:
    $thisquery = "SELECT * FROM players WHERE name='".$name."' AND pos='".$position."' AND num='".$num."' AND teamid='".$teamid."'";
    echo $thisquery; //this'll show what MySQL is being passed from the script.
    $sql = mysql_query($thisquery) or die(mysql_error());
    Post what it comes back with and we might be able to see what's what there.

    Thanks,

  7. #7
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey man,

    I got:

    num=23 , pos=c , name=britt warner , teamid=19SELECT * FROM players WHERE name='britt warner' AND pos='c' AND num='23' AND teamid='19'
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/chasesch/public_html/softball/admin/addgame.php on line 121
    http://chaseschwalbach.com

  8. #8
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, you have quotes around num/teamid values (i.e num = '23', teamid = '19') but num and teamid are integers so you don't need to quotes.

    try removing them...

  9. #9
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hEY,

    tried it, but the same results came I am really stumped on this one..
    http://chaseschwalbach.com

  10. #10
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might be a REALLY stupid suggestion, but try renaming your "pos" column to something else and try it again - rename it in the script also.

  11. #11
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KMxRetro
    This might be a REALLY stupid suggestion, but try renaming your "pos" column to something else and try it again - rename it in the script also.
    It doesn't appear to be a reserved word

  12. #12
    SitePoint Zealot
    Join Date
    Jan 2004
    Location
    Wheelersburg
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it guys...I figured it was because of this, but I've never ran into the problem before, and I don't understand why it would act like this, but this is my last question on the subject then :P

    I changed all the
    $sql to $all because earlier in the script I had used $sql as well. Is there any reason that I should be using different variables for each time I use a mysql_query?
    http://chaseschwalbach.com

  13. #13
    Feel my RewiredMind KMxRetro's Avatar
    Join Date
    Jan 2001
    Location
    Exeter, Devon, UK
    Posts
    477
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not as far a I can see.

    It depends on where and how you originally used $sql in your script. If this code you're running is inside a loop that sets $sql each time it runs, then I can see how it would cause a problem.

    I don't re-use variables most of the time - but I'm willing to bet that someone will say that it's bad practice...

  14. #14
    SitePoint Addict
    Join Date
    May 2003
    Location
    Auckland
    Posts
    309
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ignore


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •