Jump to content

Double SQL Insert?


ironside82

Recommended Posts

I have a simple form which inserts information into a database.

 

For some reason I am getting a double insert. I.e two records created from one press of the submit, I've tried stripping the code right back to see what could be causing it but with no luck,

 

Is there a obvious answer to this?

 

thanks

 

code:

            <form action="admin_addbag.php" method="post" enctype="multipart/form-data" class="uniForm">          
            <table width="734" border="0" cellpadding="2" cellspacing="0">
            <tr>
              <td width="96">Model Number</td>
              <td><label>
                <input type="text" name="model_number" id="model_number" />
              </label></td>
              <td colspan="2">(Minus last colour letter)</td>
            </tr>
            <tr>
              <td>Bag Name</td>
              <td colspan="3"><input type="text" name="bag_name" id="bag_name" /></td>
              </tr>
            <tr>
              <td>Weight</td>
              <td width="194"><input type="text" name="weight" id="weight" /></td>
              <td colspan="2">(Kg)</td>
            </tr>
            <tr>
              <td>Max Lenses</td>
              <td colspan="3"><input type="text" name="max_lenses" id="max_lenses" /></td>
              </tr>
            <tr>
              <td>Colour 1</td>
              <td><input type="text" name="colour1" id="colour1" /></td>
              <td width="99">Upload Image</td>
              <td width="329"><label>
                <input name="new_image1" id="new_image1" size="30" type="file" class="fileUpload" /></label></td>
            </tr>
            <tr>
              <td>Colour 2</td>
              <td><input type="text" name="colour2" id="colour2" /></td>
              <td>Upload Image</td>
              <td><input name="new_image2" id="new_image2" size="30" type="file" class="fileUpload" /></td>
            </tr>
            <tr>
              <td>Colour 3</td>
              <td><input type="text" name="colour3" id="colour3" /></td>
              <td>Upload Image</td>
              <td><input name="new_image3" id="new_image3" size="30" type="file" class="fileUpload" /></td>
            </tr>
            <tr>
              <td>Colour 4</td>
              <td><input type="text" name="colour4" id="colour4" /></td>
              <td>Upload Image</td>
              <td><input name="new_image4" id="new_image4" size="30" type="file" class="fileUpload" /></td>
            </tr>
          </table>
            <br />
            <label>
            <button name="submit" type="submit" class="submitButton">Submit</button>
            </label>
            </form>
          <br /></td>
        </tr>
      </table>
    </tr>
</table>
<?php
// ADD TO DATABASE

$model_number=$_POST["model_number"];
$bag_name=$_POST["bag_name"];
$weight=$_POST["weight"];
$max_lenses=$_POST["max_lenses"];
$colour1=$_POST["colour1"];
$colour2=$_POST["colour2"];
$colour3=$_POST["colour3"];
$colour4=$_POST["colour4"];
$new_image1=$_POST["colour1url"];
$new_image2=$_POST["colour2url"];
$new_image3=$_POST["colour3url"];
$new_image4=$_POST["colour4url"];



       

mysql_query("INSERT INTO bags (id, model_number, bag_name, weight, max_lenses, colour1, colour2, colour3, colour4, colour1url, colour2url, colour3url, colour4url) VALUES ('', '$model_number', '$bag_name', '$weight', '$max_lenses', '$colour1', '$colour2', '$colour3', '$colour4', '$new_image1', '$new_image2', '$new_image3', '$new_image4')");



?>

Link to comment
https://forums.phpfreaks.com/topic/111356-double-sql-insert/
Share on other sites

change button whit this one: <input type='submit' name='save' value='Send now'>

 

php code:

<?php
//first check if press submit button
if (isset($_POST['save'])) {
// ADD TO DATABASE

$model_number=$_POST["model_number"];
$bag_name=$_POST["bag_name"];
$weight=$_POST["weight"];
$max_lenses=$_POST["max_lenses"];
$colour1=$_POST["colour1"];
$colour2=$_POST["colour2"];
$colour3=$_POST["colour3"];
$colour4=$_POST["colour4"];
$new_image1=$_POST["colour1url"];
$new_image2=$_POST["colour2url"];
$new_image3=$_POST["colour3url"];
$new_image4=$_POST["colour4url"];

$result = mysql_query("INSERT INTO bags (id, model_number, bag_name, weight, max_lenses, colour1, colour2, colour3, colour4, colour1url, colour2url, colour3url, colour4url) VALUES ('', '$model_number', '$bag_name', '$weight', '$max_lenses', '$colour1', '$colour2', '$colour3', '$colour4', '$new_image1', '$new_image2', '$new_image3', '$new_image4')");

if ($result) { echo "Success!"; }

}
?>

Link to comment
https://forums.phpfreaks.com/topic/111356-double-sql-insert/#findComment-571751
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.