SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Weird SQL error...

    This is my code:

    PHP Code:
    $thisscrewed mysql_query("SELECT * FROM viewed WHERE userid='$username' && postid='$posts123456[subject]'");
    while(
    $viewed2=mysql_fetch_array($thisscrewed))

    And I get an error on the second line there. the while. That means it's in the select query, right?

    Well, I tried this query in phpMyAdmin, and it works.

    This is being looped for every post in forum.

    It is only on some of them for some weird reason.

    Any ideas?

    Thanks,
    ~someonewhois

  2. #2
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try building your sql query first, then sending it...
    PHP Code:
    $screwyquery "SELECT * FROM viewed WHERE userid='$username' && postid='".$posts123456['subject']."'"); // notice also the single quotes around subject
    $stillscrewed mysql_query($screwyquery) or die(mysql_error()); 
    or...should $posts123456['subject'] actually be $posts123456[$subject] ? depends, i don't know your code...
    give it a twirl...you never know
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Weird SQL error...

    try putting quotes around your array index and delimit the array variable with braces:
    Code:
    {$posts123456['subject']}
    heh i was slow ... either way should work though

  4. #4
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's another fetch array, it's ['subject']...



    Thanks,
    ~someonewhois

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the error:

    You have an error in your SQL syntax near 'MT ESTING!'' at line 1

    Any before it was in 2 places, but I guess it died before it could get to the other one...

    MT ESTING must be the subject...

    Thanks,
    ~someonewhois

    P.S. Any ideas? It works for the rest?

  6. #6
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not sure, but if my guess is correct, and subject is indeed "MT ESTING", then the problem might be that your associative array cannot handle having a space between MT and ESTING. if so, you must find another way of referencing your array...
    (sorry for being cryptic, but it's time for sleepies over here )
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i assume the text is something like I'MT ESTING, which is supposed to be I'M TESTING. probably need to addslashes() on username and/or subject.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  8. #8
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    larry...spiffy new icon btw !
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  9. #9
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OH!

    Yes, I suspected the space at first, but there are others with that error.

    I'll check, it must be the slashes!

    Thanks,
    ~someonewhois

    P.S. I agree, nice avatar!

  10. #10
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, that fixed it!

    Thanks a lot,
    ~someonewhois


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
  •