Solved

Dreamweaver CS5 submits the form automatically

Posted on 2010-11-20
13
325 Views
Last Modified: 2012-05-10
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
Comment
Question by:babak62
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 34180987
look for any onload event code that may be causing this, the submit code above looks fine.
0
 
LVL 9

Expert Comment

by:TonyReba
ID: 34181033
can you paste the remainding code so we can look at it
0
 

Author Comment

by:babak62
ID: 34181055
Thanks for the response but there is no onload in the document.
0
On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34181102
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
 

Author Comment

by:babak62
ID: 34181110
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
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34181143
Huh, weird.  That's correct code.

Are you sure you don't have a stuck "Enter" key on the keyboard or something.
0
 

Author Comment

by:babak62
ID: 34181162
sure I don't but thanks for asking.
0
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 250 total points
ID: 34181187
>> 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
 

Author Closing Comment

by:babak62
ID: 34181271
PERFECT HELP thanks a lot
0
 
LVL 9

Expert Comment

by:TonyReba
ID: 34181304
What was the problem?
0
 

Author Comment

by:babak62
ID: 34181312
Have no idea but what you said just fixed it!!!!!!!!!!!!!
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 34181700
>> 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
 

Author Comment

by:babak62
ID: 34181734
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: 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question