Double Submit Problem
Posted: Tue Aug 31, 2010 3:26 am
Hi all,
I'm having a problem with a script running twice and inserting data twice into my MySQL database. I've researched this problem but have not found the solution. Any suggestions? Thanks in advance.
I'm having a problem with a script running twice and inserting data twice into my MySQL database. I've researched this problem but have not found the solution. Any suggestions? Thanks in advance.
Code: Select all
<?php
$con = mysql_connect("xxxx","xxxx","xxxx");
mysql_select_db("neesleysqltest", $con);
if (isset($_POST['submit'])) {
$ins = "INSERT INTO schedule
VALUES (ID, '$_POST[date]','$_POST[jakes]','$_POST[gin]','$_POST[wagon]','$_POST[stumble]','$_POST[hatch]','$_POST[step]','$_POST[sheets]')";
if (!mysql_query($ins,$con))
{
die('Error: ' . mysql_error());
}
echo "<b>Schedule added.</b>";
// Execute query
mysql_query($ins,$con);
mysql_close($con);
}
else
{
?>
<table id="box-table-b">
<tr>
<th>Create New Day</th>
</tr>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<tr><td>Date: <input type="text" name="date"></td></tr>
<tr><td>Jakes:
<select name="jakes">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>Gin Mill:
<select name="gin">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>Off The Wagon:
<select name="wagon">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>The Stumble Inn:
<select name="stumble">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>Down The Hatch:
<select name="hatch">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>The 13th Step:
<select name="step">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td>3 Sheets Saloon:
<select name="sheets">
<?php
$employees = mysql_query("SELECT first_name FROM employees");
while($row = mysql_fetch_array($employees))
{
echo "<option>" . $row['first_name'] . "</option>";
}
echo "</select></td></tr>";
?>
<trd><td><input type="submit" name="submit" value="Create New Day"></td></tr>
</form>
<?php
}
mysql_close($con);
?>