Unwanted INSERT INTO extra entry

Discussion in 'PHP' started by tin2mon, Oct 27, 2010.

  1. #1
    Hi,

    The contents of a FORM are received from a previous page and stored in the variable $EDIT.

    I am then sending the contents of $EDIT to a MySQL database:

    It works just fine: the contents of $EDIT are sent to the database.

    However... and this is what's driving me nuts; it sends TWO entries, a first and a second entry - the first entry, including the contents of $EDIT and then a second and unwanted entry with no text input, just a blank area where the text should be.

    I get two duplicate records, but one has text and the other has just a blank space.

    How do I stop it from sending two entries?
    Any idea why it's send a second entry with nothing in it, i.e. $EDIT with no data?
    Is there any way I can limit the entry to just 1?
    Am I doing something fundamentally wrong??

    Thanks in advance for your tips and ideas. It's appreciated.
     
    tin2mon, Oct 27, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Does your form reload the same page ?

    You could consider adding an if empty statement:

    If the variable $name for example has no data, the query wont run

    
    <?php
    
    require ('db_connect.inc.php');
    if (empty($Name)) { 
    //do nothing
    }else{
    $result = mysql_query("INSERT INTO TrackReviews (ID, Name, Review, FixedID, ModifiedDate) VALUES ('NULL', '$Name', '$EDIT', '$FixedIDvalue', NOW())");
    }
    
    ?> 
    
    PHP:
     
    MyVodaFone, Oct 27, 2010 IP
  3. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #3
    I don't see a problem with your query however remove the quotes from the NULL (or better don't mention the ID).

    Chances are theirs a problem with your validation earlier on.
     
    danx10, Oct 27, 2010 IP
  4. S1M

    S1M Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It sounds like you're calling the query code twice. Is it in a looping construct like a foreach or do while? Do the other vars have any value? Is $EDIT the only one empty? That may help you track down where it's getting repeated.
     
    S1M, Oct 27, 2010 IP