I'm getting duplicate entries in database.

Discussion in 'PHP' started by countrydj, Apr 13, 2011.

  1. #1
    Hi Guys...


    I'm getting duplicate entries in mysql database when submitting a new item from a form.
    I initially loaded the database via IMPORT function in phpMyAdmin.

    This is my input form:
    <center>
    <br />
    <FONT SIZE="5" ><b>Add Item Template</b></FONT>
    <br />

    <form action="add_items.php" method="GET">
    <table width="100%" border="0" align="RIGHT" cellspacing="2" cellpadding="2">
    <tr>
    <td align="RIGHT" valign="top"><font size=2><b> Group: </td>
    <td align="LEFT">
    <select name="grtype">
    <option value="PLEASE SELECT">PLEASE SELECT
    <option value="Alloy Silencers">Alloy Silencers
    <option value="Carbon Silencers">Carbon Silencers
    <option value="Titanium">Titanium
    <option value="Complete Systems">Complete Systems
    <option value="Pipe Kits">Pipe Kits
    <option value="Down Pipes">Down Pipes
    <option value="Meggaphones (Un-Silenced)">Meggaphones (Un-Silenced)
    <option value="Meggaphones (Silenced)">Meggaphones (Silenced)
    <option value="Early Stock / Bygone Days">Early Stock / Bygone Days


    </select>
    </td>
    </tr>

    <tr>
    <td align="RIGHT"><font size=2><b>Description: </b></font></td>
    <td align="LEFT"><input type="text" size=35 name="description"></td>

    </tr>

    <tr>
    <td align="RIGHT"><font size=2><b>Comment: </b></font></td>
    <td align="LEFT"><input type="text" size=35 name="comment"></td>

    </tr>

    <tr>
    <td align="RIGHT"><font size=2><b>Quantity: </b></font></td>
    <td align="LEFT"><input type="text" size=35 name="quantity"></td>
    </tr>

    <tr>
    <td align="RIGHT"><font size=2><b>Price: </td>
    <td align="LEFT"><input type="text" size=35 name="price"> </td>
    </tr>

    <tr>
    <td align="RIGHT"><font size=2><b>Order: </font></td>
    <td align="LEFT"><input type="text" size=35 name="catorder"></td>
    </tr>

    <tr>
    <td align="RIGHT"></b></font></td>
    <td align="CENTER"><input type="button" value="Send" onclick="post()">
    <input type="reset" value="Clear"></td>

    <!--################## END STANDARD TEMPLATE ONE ########################-->

    <input type="hidden" name="act" value="add"></input>
    <input type="hidden" name="type2" value="all"></input>
    </form>
    </td>
    </tr>
    </table>

    </center>



    This is my processing script:


    <?
    require("global.php");

    $template = join('',file('add_items.tpl'));
    $content = join('',file('add_items.txt'));


    $grtype = $_REQUEST['grtype'];
    $description = $_REQUEST['description'];
    $comment = $_REQUEST['comment'];
    $quantity = $_REQUEST['quantity'];
    $price = $_REQUEST['price'];
    $type2 = $_REQUEST['type2'];
    $status = $_REQUEST['status'];


    if($action=="add"){



    $qry = "INSERT INTO " . $vars["table directory"];
    $qry .= "(id,grtype,description,comment,quantity,price,type,type2,catorder,status)";
    $qry .= "VALUES ('','$grtype','$description','$comment','$quantity','$price','$type','$type2','$catorder','1')";

    if(!($results = mysql_query($qry, $link))){
    displayErrMsg(sprintf("Error in executing %s query", $qry));
    displayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error($link)));
    exit();
    }

    # SEND RESPONSE

    $template = str_replace("[main content]",$content,$template);

    print $template;


    }

    ?>



    I think that it might be something to do with the RESPONSE section.
    If I delete that and replace it with
    print "Thank you";
    I only get one entry in the database.

    However, I do need to return the input form in order to keep entering new items into the database.

    I would really appreciate any help and advise possible.

    Sorry for such a long post.
    I wanted to give as much information as possible.


    Thanks,

    John C
     
    countrydj, Apr 13, 2011 IP