SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Not Inserting New Record

    #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 'Giff Gaff - Free Sim'',''AdWarm Limited'')' at line 1
    PHP Code:
    INSERT INTO affprograms VALUES ('','2','1','Pending',''Giff Gaff Free Sim'',''AdWarm Limited''
    Whats wrong with my MySQL query?

    The first '' is left blank as its Auto Increment.

    Any help would be great.

    Thanks
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    The coloration in your code there should be a hint. Look at the color of Pending, then at the color of Giff Gaff....

  3. #3
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah ok so i had to take the '' out of the query around those 2 as for some reason it was adding them automatically. Thanks StarLion. I have another problem now, I've changed all the pages to make it SQL Injection proof but now im getting a few problems for example:

    PHP Code:
    $query sprintf("SELECT SUM(Payout) AS 'payout' FROM affleads WHERE `AffID` = '%s' AND `Date` LIKE '%%s%s%'",
                
    quote_smart($affid),  
                
    quote_smart($current_year),
                
    quote_smart($current_month)); 
    SELECT SUM(Payout) AS 'payout' FROM affleads WHERE `AffID` = '2' AND `Date` LIKE '%s2011
    As you can see theres still a %s in there that never got replaced, why is this happening?

    Yea i have % at the beginning and end as its a wildcard.

    Thanks
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!

  4. #4
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    69 Post(s)
    Tagged
    0 Thread(s)
    It's a translation issue. % is the escape character in sprintf - if you want a litteral %, you put %%.
    Lets look at that section of the code.

    '%%s%s%'

    Read left to right, and it says "Put a literal %, then an s (because the % is not a special character anymore), then put in a string, then escape a ' (which does nothing, because %' isnt a valid escape sequence in sprintf.

    The correct code you're looking for there, is '%%%s%s%%'
    *gets out crayons to show how that gets translated*

    Output a literal %.
    Parse a String
    Parse Another String
    Output a literal %.

  5. #5
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah right ok thanks again StarLion
    You're Help Does Not Go Unnoticed, I have So Far Donated 25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!


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
  •