www.webdeveloper.com
Results 1 to 15 of 15

Thread: ghost entries

  1. #1
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18

    ghost entries

    hello all

    i tried looking for an answer on google and here for this but couldnt find any and this is making me go nuts


    my prob is:
    i have a php page that retrieves data from a form using extract($_POST);
    and then correctly adds the data to a database using the usual mysql insert command

    problem is:
    whenever i insert an item, the data is inserted correctly but there's an additional empty entry inserted out of nowhere,
    i have no clue why or from where

    the moment i insert the data into the database, i refresh the phpmyadmin page almost directly and i see my new entry alone , but like another second later, i refresh, and the empty entry is inserted out of nowhere

    any idea guys?

  2. #2
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    I guess that you are running the mysql query and then error checking the query to see if it inserted. Can you post a block of your PHP around your INSERT statement for us to look at?

  3. #3
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    hello
    this is it:


    extract($_POST);

    //there's bunch of code here that outputs the variable on screen in a table

    $insert_query = "insert into dogs values('','$name', '$DOB', '$country_en', '$country_fr', '$pedigree', '$full_image_path', '$comment_en', '$comment_fr', '$vendre')";

    mysql_query($insert_query);


    if (mysql_affected_rows() != 1) {
    print "An error occurred";
    } else {
    print "";
    }






    what am doing is having the database open in phpmyadmin ("broswe"), and i refresh to c if the entry was added, but on my 2nd refresh,i see a blank ghost entry out of nowhere

    thanks
    Last edited by karxix; 01-02-2007 at 05:11 AM.

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Can you code this right before mysql_query($insert_query);:
    PHP Code:
    print "<pre>";
    print_r($insert_query);
    print 
    "</pre>"
    and share with us what is displayed on screen?

    You may have an unlucky combination of characters in one of the variables, which could lead to MySQL believing that you are trying to do a multiple insert.

  5. #5
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    ok,
    this is it:
    insert into dogs values('','test name', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', 'ped.jpg','photo.jpg', 'comment, english', 'comment, french', '0')


    there was no blank entry afterwrds this time though

    it's weird,
    i just tried many entries after each other now, and i dont seem to get any blank ones for some reason


    ah ok, after some testing again
    apparently the blank entry is only appearing when i am not inputting anything in certain fields as in here:
    insert into dogs values('','test name1', '22/10/1995', 'lebanon', 'liban', 'l.o.s.h', '','', 'comment, english...', 'comment, french.', '1')

    what's the solution to this prob?
    and what exactly is causing this to happen?

  6. #6
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    I don't know if this is really causing the problem, but this will not work:
    PHP Code:
    insert into dogs values('','test name''22/10/1995''lebanon''liban''l.o.s.h''ped.jpg','photo.jpg''comment, english''comment, french''0'
    because they are so-called "unescaped" commas in your values. You will have to use addslashes() on each variable that is likely to contained "unauthorized" characters before inserting in the database - probably best to do it on all character variables.

    In the above code, MySQL thinks you're trying to insert not 11 but 13 fields...

    Try that and see what happens.

    a+

  7. #7
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    ok
    thanks alot
    will keep u updated what happens

    any explanation on why when all fields are filled there's no problem, but when one is left empty, the prob occurs?

  8. #8
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    No, I can't tell you why this is happening - other than that there's a coding error somewhere.

  9. #9
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    hmm ok

    what type of coding error...or what makes u think there's a coding error?
    so i can at least know how/where to check for it

    thanks

  10. #10
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    It's hard for me to tell from afar. I just know that most inserts don't end up making "ghost entries". I can practically rule out MySQL as the culprit.

    That leaves your code or the content of the variables you are trying to insert, which brings us back to your code, unfortunately.

    What I do I know is that your SQL looks like this:
    PHP Code:
     insert into dogs values('','test name''22/10/1995''lebanon''liban''l.o.s.h''ped.jpg','photo.jpg''comment, english''comment, french''0'
    but it should look like this:
    PHP Code:
     insert into dogs values('','test name''22/10/1995''lebanon''liban''l.o.s.h''ped.jpg','photo.jpg''comment\, english''comment\, french''0'

  11. #11
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    alright
    many thanks
    i will look into this tomorrow afternoon/night as i got an exam before that
    and will let you know how it all works out

  12. #12
    Join Date
    Apr 2005
    Location
    Bathurst, NSW, Australia
    Posts
    3,357
    NightShift58,
    a) commas don't need to be escaped (or can you provide me a link to where this is stated otherwise);
    b) addslashes() only places backslashes before a single quote ('), double quote ("), backslash (\) and NUL (the NULL byte) characters, not a comma anyway;
    c) you probably should use mysql_real_escape_string() rather than addslashes() for MySQL queries.

    karxix would you mind posting your whole code then aswell as the database structure

  13. #13
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    Quote Originally Posted by bathurst_guy
    Nightshift...
    You're right. Don't know where my thoughts were.
    Last edited by NightShift58; 01-04-2007 at 09:14 AM.

  14. #14
    Join Date
    Feb 2004
    Location
    lebanon
    Posts
    18
    $_POST = array_map('mysql_real_escape_string', $_POST);

    i saw this on the php manual,
    would it work?


    also as a side question, if u use this:
    imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    how do i know where the new image is stored, or how can i move it to where i want, rename it...i couldnt easily find that in the manual, thought u can point me out to what to look for (ps: all variables are set right )

    thanks
    Last edited by karxix; 01-04-2007 at 10:05 AM.

  15. #15
    Join Date
    Jun 2006
    Posts
    472
    If you are not specifying the column names and you are using auto_increment you should
    use NULL as the value not ''
    PHP Code:
     insert into dogs values(NULL,'test name''22/10/1995''lebanon''liban''l.o.s.h''ped.jpg','photo.jpg''comment, english''comment, french'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles