• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

Dreamweaver CS5 submits the form automatically

Hello everybody;
I have a form in CS5 in php and trying to insert records to the DB but the form submits onload also when I refresh the page I get a new record in the db.  Here is the code for the submit part please let me know if you need to see more.  Best to you all
Bobby


        <input name="Submit Media" type="submit" id="Submit Media"  onclick="Submit"/>

      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
    <input type="hidden" name="MM_insert" value="insert media" />
</form>
0
babak62
Asked:
babak62
  • 6
  • 4
  • 2
  • +1
1 Solution
 
Jerry MillerCommented:
look for any onload event code that may be causing this, the submit code above looks fine.
0
 
TonyRebaCommented:
can you paste the remainding code so we can look at it
0
 
babak62Author Commented:
Thanks for the response but there is no onload in the document.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Jason C. LevineNo oneCommented:
babak62,

My guess is that you have no checks in the PHP code to see if the form has been submitted so the PHP behaviors fire when you load the page.  Please show all of your page code, PHP and HTML.
0
 
babak62Author Commented:
sure here is my code

<?php require_once('Connections/iran79.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "insert media")) {
  $insertSQL = sprintf("INSERT INTO media_owner_info (First_Name, Last_Name, Email_Address, `Business Phone`, Home_Phone, Mobile_Phone, Address, Zip, `State`, City, Country) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['First Name'], "text"),
                       GetSQLValueString($_POST['Last Name'], "text"),
                       GetSQLValueString($_POST['Email Address'], "text"),
                       GetSQLValueString($_POST['Business Phone'], "text"),
                       GetSQLValueString($_POST['Home Phone'], "text"),
                       GetSQLValueString($_POST['Mobile Phone'], "text"),
                       GetSQLValueString($_POST['Address'], "text"),
                       GetSQLValueString($_POST['Zip'], "text"),
                       GetSQLValueString($_POST['US States'], "text"),
                       GetSQLValueString($_POST['City'], "text"),
                       GetSQLValueString($_POST['Countries'], "text"));

  mysql_select_db($database_iran79, $iran79);
  $Result1 = mysql_query($insertSQL, $iran79) or die(mysql_error());
}

mysql_select_db($database_iran79, $iran79);
$query_Recordset1 = "SELECT * FROM lookup_media_genere";
$Recordset1 = mysql_query($query_Recordset1, $iran79) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $editFormAction; ?>" id="insert_media" name="insert media" method="POST">
  <table width="1054" border="1">
    <tr>
      <th colspan="5" scope="col">Media Insert Page</th>
    </tr>
    <tr>
      <td width="207">280</td>
      <td width="198">&nbsp;</td>
      <td width="178">&nbsp;</td>
      <td width="321">&nbsp;</td>
      <td width="116">&nbsp;</td>
    </tr>
    <tr>
      <td>Media Name</td>
      <td><label>
        <input type="text" name="Media Name" id="Media Name" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Media Name Farsi</td>
      <td><label>
        <input type="text" name="Media Name Farsi" id="Media Name Farsi" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Genere_Lookup</td>
      <td><label>
        <select name="Genere_Lookup1" id="Genere_Lookup1" title="">
          <?php
do {  
?>
          <option value="<?php echo $row_Recordset1['Genere']?>"><?php echo $row_Recordset1['Genere']?></option>
          <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
        </select>
     </label></td>
      <td><label>
        <select name="Genere_Lookup2" id="Genere_Lookup2" title="<?php echo $row_Recordset1['Genere']; ?>">
          <?php
do {  
?>
          <option value="<?php echo $row_Recordset1['Genere']?>"><?php echo $row_Recordset1['Genere']?></option>
          <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
        </select>
      </label></td>
      <td><label>
        <select name="Genere_Lookup3" id="Genere_Lookup3" title="<?php echo $row_Recordset1['Genere']; ?>">
          <?php
do {  
?>
          <option value="<?php echo $row_Recordset1['Genere']?>"<?php if (!(strcmp($row_Recordset1['Genere'], "Select"))) {echo "selected=\"selected\"";} ?>><?php echo $row_Recordset1['Genere']?></option>
          <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
	  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
        </select>
      </label></td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>First Name</td>
      <td><label>
        <input name="First Name" type="text" id="First Name" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Last Name</td>
      <td><label>
        <input name="Last Name" type="text" id="Last Name" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Email Address</td>
      <td><label>
        <input type="text" name="Email Address" id="Email Address" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Business Phone</td>
      <td><label>
        <input type="text" name="Business Phone" id="Business Phone" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Home Phone</td>
      <td><label>
        <input type="text" name="Home Phone" id="Home Phone" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Mobile Phone</td>
      <td><label>
        <input type="text" name="Mobile Phone" id="Mobile Phone" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Address</td>
      <td><label>
        <input type="text" name="Address" id="Address" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Zip</td>
      <td><label>
        <input type="text" name="Zip" id="Zip" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>State</td>
      <td><label>
        <select name="US States">
          <option selected="selected">Choose a state</option>
          <option value="AL">Alabama</option>
          <option value="AK">Alaska</option>
          <option value="AZ">Arizona</option>
          <option value="AR">Arkansas</option>
          <option value="CA">California</option>
          <option value="CO">Colorado</option>
          <option value="CT">Connecticut</option>
          <option value="DE">Delaware</option>
          <option value="FL">Florida</option>
          <option value="GA">Georgia</option>
          <option value="HI">Hawaii</option>
          <option value="ID">Idaho</option>
          <option value="IL">Illinois</option>
          <option value="IN">Indiana</option>
          <option value="IA">Iowa</option>
          <option value="KS">Kansas</option>
          <option value="KY">Kentucky</option>
          <option value="LA">Louisiana</option>
          <option value="ME">Maine</option>
          <option value="MD">Maryland</option>
          <option value="MA">Massachusetts</option>
          <option value="MI">Michigan</option>
          <option value="MN">Minnesota</option>
          <option value="MS">Mississippi</option>
          <option value="MO">Missouri</option>
          <option value="MT">Montana</option>
          <option value="NE">Nebraska</option>
          <option value="NV">Nevada</option>
          <option value="NH">New Hampshire</option>
          <option value="NJ">New Jersey</option>
          <option value="NM">New Mexico</option>
          <option value="NY">New York</option>
          <option value="NF">Newfoundland</option>
          <option value="NC">North Carolina</option>
          <option value="ND">North Dakota</option>
          <option value="OH">Ohio</option>
          <option value="OK">Oklahoma</option>
          <option value="OR">Oregon</option>
          <option value="PA">Pennsylvania</option>
          <option value="RI">Rhode Island</option>
          <option value="SC">South Carolina</option>
          <option value="SD">South Dakota</option>
          <option value="TN">Tennessee</option>
          <option value="TX">Texas</option>
          <option value="UT">Utah</option>
          <option value="VT">Vermont</option>
          <option value="VA">Virginia</option>
          <option value="WA">Washington</option>
          <option value="DC">Washington, D.C.</option>
          <option value="WV">West Virginia</option>
          <option value="WI">Wisconsin</option>
          <option value="WY">Wyoming</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>City</td>
      <td><label>
        <input type="text" name="City" id="City" />
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>Country</td>
      <td><label>
        <select name="Countries">
          <option selected="selected">Choose a country</option>
          <option value="AR">Argentina</option>
          <option value="AU">Australia</option>
          <option value="AT">Austria</option>
          <option value="BS">Bahamas</option>
          <option value="BE">Belgium</option>
          <option value="BO">Bolivia</option>
          <option value="BR">Brazil</option>
          <option value="CA">Canada</option>
          <option value="CH">Chile</option>
          <option value="CN">China</option>
          <option value="CO">Colombia</option>
          <option value="CR">Costa Rica</option>
          <option value="HR">Croatia</option>
          <option value="CU">Cuba</option>
          <option value="CZ">Czech, Rep.</option>
          <option value="DK">Denmark</option>
          <option value="DO">Dominican, Rep.</option>
          <option value="EC">Ecuador</option>
          <option value="EG">Egypt</option>
          <option value="SV">El Salvador</option>
          <option value="FI">Finland</option>
          <option value="FR">France</option>
          <option value="DE">Germany</option>
          <option value="GR">Greece</option>
          <option value="GT">Guatemala</option>
          <option value="HN">Honduras</option>
          <option value="HK">Hong Kong</option>
          <option value="IN">India</option>
          <option value="IE">Ireland</option>
          <option value="IL">Israel</option>
          <option value="IT">Italy</option>
          <option value="JM">Jamaica</option>
          <option value="JP">Japan</option>
          <option value="LU">Luxembourg</option>
          <option value="MX">Mexico</option>
          <option value="MA">Morocco</option>
          <option value="NL">Netherlands</option>
          <option value="NZ">New Zealand</option>
          <option value="NI">Nicaragua</option>
          <option value="NG">Nigeria</option>
          <option value="NO">Norway</option>

          <option value="PY">Paraguay</option>
          <option value="PE">Peru</option>
          <option value="PL">Poland</option>
          <option value="PT">Portugal</option>
          <option value="PR">Puerto Rico</option>
          <option value="RU">Russia</option>
          <option value="SA">Saudi Arabia</option>
          <option value="ZA">South Africa</option>
          <option value="ES">Spain</option>
          <option value="SE">Sweden</option>
          <option value="CH">Switzerland</option>
          <option value="TW">Taiwan</option>
          <option value="TR">Turkey</option>
          <option value="UK">United Kingdom</option>
          <option value="US">United States</option>
          <option value="UY">Uruguay</option>
          <option value="VE">Venezuela</option>
          <option value="OT">Other...</option>
        </select>
      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
        <label>
           <input name="Submit Media" type="submit" id="Submit Media"  onclick="Submit"/>

      </label></td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
    <input type="hidden" name="MM_insert" value="insert media" />
</form>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Open in new window

0
 
Jason C. LevineNo oneCommented:
Huh, weird.  That's correct code.

Are you sure you don't have a stuck "Enter" key on the keyboard or something.
0
 
babak62Author Commented:
sure I don't but thanks for asking.
0
 
Jason C. LevineNo oneCommented:
>> when I refresh the page I get a new record in the db.

If you refresh the page after a form submission, the form will submit again.

Close the browser, access the page.  Does it submit the form on the first access?
0
 
babak62Author Commented:
PERFECT HELP thanks a lot
0
 
TonyRebaCommented:
What was the problem?
0
 
babak62Author Commented:
Have no idea but what you said just fixed it!!!!!!!!!!!!!
0
 
Jason C. LevineNo oneCommented:
>> What was the problem?

When you submit a form with POST, the POST headers stay in the browser cache so reloads will resubmit the form.  Once the asker closed the browser and dumped the cache, reloads will no longer submit the form until a new form is submitted.
0
 
babak62Author Commented:
Thanks a lot jason for the great help.  Here I posted an another question please take a look at it when you have time

http://www.experts-exchange.com/Web_Development/Scripting/PHP/PHP_Databases/Q_26629361.html?cid=1575#a34181649 

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now