Solved

Dreamweaver CS5 submits the form automatically

Posted on 2010-11-20
13
319 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dreamweaver not "Putting" files to server 15 585
Lock Form Controls 3 306
Dreamweaver Styles 7 396
Dreamweaver CS6 Sites Setup 2 422
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…
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now