Inserting Unwanted Blank Record
Posted by: twilitegxa (---.hsd1.tn.comcast.net)
Date: August 08, 2009 11:58PM

Every time my insert statement is issued, it inserts the data from my from into the table in the database, but it is also inserting an unwanted blank record as well. Can anyone help me out with why and how to fix it? Here is my page with my insert statement:

<?php

session_start();

//function for determining birth_year
function yearOfBirth ($day, $month, $age)
{
$now = strtotime('1992-03-23');

$yob = date('Y', $now) - $age;

if (date('md', $now) < sprintf('%02d%02d', $month, $day)) $yob--;

return $yob;
}

$year = yearOfBirth($_POST['birth_date'], $_POST['birth_month'], $_POST['age']);
//end of function for determining birth_year

?>

<?php
//connect to server and select database
$conn = mysql_connect("localhost", "root", ""winking smiley
or die(mysql_error());
mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue first query; insert values into scouts table
$add_fdark_warrior = "insert into fdark_warrior values ('', now(), '$_SESSION[userName]', '$_POST[name]', '$_POST[name]', '$_POST[element_of_influence]', '$_POST[age]', '$_POST[birth_month]', '$_POST[birth_date]', '$year', '$_POST[blood_type]', '$_POST[hobbies]', '$_POST[favorite_color]', '$_POST[favorite_gemstone]', '$_POST[favorite_food]', '$_POST[least_favorite_food]', '$_POST[strengths]', '$_POST[weaknesses]', '$_POST[mission]', '$_POST[goal]', '".mysql_real_escape_string($_POST['biography'])."', '$_POST[height_feet]', '$_POST[height_inches]')";
mysql_query($add_fdark_warrior, $conn) or die(mysql_error());

//get identity from last query
$identity = $_POST['name'];

//create and issue second query; insert values into stats table
//$add_stats = "insert into stats values ('', '$identity', '$_POST[body]', '$_POST[mind]', '$_POST[soul]')";
//mysql_query($add_stats, $conn) or die(mysql_error());

//create and issue third query; insert values into derived_values table
//$add_derived_values = "insert into derived_values values ('', '$identity', '$_POST[health]', '$_POST[energy]', '$_POST[acv1]', '$_POST[acv2]', '$_POST[dcv1]', '$_POST[dcv2]', '$_POST[total_cp]')";
//mysql_query($add_derived_values, $conn) or die(mysql_error());

//create message for user
$msg = "<p>The character, <strong>$identity</strong> was created.</p>";
?>
<html>
<head>
<title>Sailor Moon RPG - New Character Created - <?php echo $identity; ?></title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css);
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"winking smiley; ?>
<div id="main">
<?php include("includes/log.php"winking smiley; ?>
<?php include("mainnav.php"winking smiley; ?>
<h1>New Character Created - <?php echo $identity; ?></h1>
<?php print $msg; ?>
</div>
<?php include("bottomnav.php"winking smiley; ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br />
trademarks of Naoko Takeuchi.</p>
<p>Copyright &copy; 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="[validator.w3.org]; target="_blank"><img src="[www.w3.org]; alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="[jigsaw.w3.org]; target="_blank"><img class="c2" src="[jigsaw.w3.org]; alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

Options: ReplyQuote
Re: Inserting Unwanted Blank Record
Posted by: toumimi (---.117.116-78.rev.gaoland.net)
Date: August 09, 2009 12:18AM

There is no form in your given code.
If you are not using the same page to submit parameters and to insert into mysql, you are probably using a header function, then try to add exit() just after this function.
Note that sometimes, the browser reload itself the page and do a double submit..

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Inserting Unwanted Blank Record
Posted by: twilitegxa (---.hsd1.tn.comcast.net)
Date: August 09, 2009 12:51AM

Here is my form:

<?php

session_start();

//Access Tracking Snippet

//set up static variables
$page_title = "fdark_warrior.php";
$user_agent = getenv("HTTP_USER_AGENT"winking smiley;
$date_accessed = date("Y-m-d"winking smiley;

//connect to server and select database
$conn = mysql_connect("localhost", "root", ""winking smiley
or die(mysql_error());
$db = mysql_select_db("smrpg", $conn) or die(mysql_error());

//create and issue query
$sql = "insert into access_tracker values
('', '$page_title', '$user_agent', '$date_accessed')";
mysql_query($sql,$conn);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sailor Moon RPG - Character Creation Form | Female Dark Warrior</title>
<style type="text/css" media="screen">
/*<![CDATA[*/
@import url(global.css);
/*]]>*/
</style>
</head>
<body>
<!-- HEADER -->
<h1 class="logo">Sailor Moon RPG</h1>
<!-- /HEADER -->
<?php include("topnav.php"winking smiley; ?>
<div id="main">
<?php include("includes/log.php"winking smiley; ?>
<?php include("mainnav.php"winking smiley; ?>
<form action="insert_fdark_warrior.php" method="post">
<h1>Step 2: Character Outline - Creation</h1>
<h2><u>Female Dark Warrior Profile</u></h2>
<table border="0">
<td>Character Name:</td>
<td><input type="text" name="name" size="30" maxlength="100"></td>
</tr>
<tr>
<td>Element Of Influence (if any):</td>
<td>
<SELECT NAME="element_of_influence" SIZE="1">
<OPTION value="Water">Water</OPTION>
<OPTION value="Fire">Fire</OPTION>
<OPTION value="Wood/Lightning">Wood/Lightning</OPTION>
<OPTION value="Metal">Metal</OPTION>
<OPTION value="Earth">Earth</OPTION>
<OPTION value="Time">Time</OPTION>
<OPTION value="None">None</OPTION>
</SELECT> <a href="elements.php" title="Help!"><img src="question.gif" /></a></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" name="age" size="2" maxlength="2"></td>
</tr>
<tr>
<td>Date Of Birth:</td>
<td><SELECT NAME="birth_month" SIZE="1">
<OPTION value="01">January</OPTION>
<OPTION value="02">February</OPTION>
<OPTION value="03">March</OPTION>
<OPTION value="04">April</OPTION>
<OPTION value="05">May</OPTION>
<OPTION value="06">June</OPTION>
<OPTION value="07">July</OPTION>
<OPTION value="08">August</OPTION>
<OPTION value="09">September</OPTION>
<OPTION value="10">October</OPTION>
<OPTION value="11">November</OPTION>
<OPTION value="12">December</OPTION>
</SELECT>

<SELECT NAME="birth_date" SIZE="1">
<OPTION value="01">1</OPTION>
<OPTION value="02">2</OPTION>
<OPTION value="03">3</OPTION>
<OPTION value="04">4</OPTION>
<OPTION value="05">5</OPTION>
<OPTION value="06">6</OPTION>
<OPTION value="07">7</OPTION>
<OPTION value="08">8</OPTION>
<OPTION value="09">9</OPTION>
<OPTION value="10">10</OPTION>
<OPTION value="11">11</OPTION>
<OPTION value="12">12</OPTION>
<OPTION value="13">13</OPTION>
<OPTION value="14">14</OPTION>
<OPTION value="15">15</OPTION>
<OPTION value="16">16</OPTION>
<OPTION value="17">17</OPTION>
<OPTION value="18">18</OPTION>
<OPTION value="19">19</OPTION>
<OPTION value="20">20</OPTION>
<OPTION value="21">21</OPTION>
<OPTION value="22">22</OPTION>
<OPTION value="23">23</OPTION>
<OPTION value="24">24</OPTION>
<OPTION value="25">25</OPTION>
<OPTION value="26">26</OPTION>
<OPTION value="27">27</OPTION>
<OPTION value="28">28</OPTION>
<OPTION value="29">29</OPTION>
<OPTION value="30">30</OPTION>
<OPTION value="31">31</OPTION>
</SELECT> </td>
</tr>
<tr>
<td>Height:</td>
<td><input type="text" name="height_feet" size="2" maxlength="2"> feet <input type="text" name="height_inches" size="2" maxlength="2"> inches</td>

</tr>
<tr>
<td>Blood Type:</td>
<td><input type="text" name="blood_type" size="4" maxlength="4"> <a href="bloodtype.php" title="Help!"><img src="question.gif" /></a> </td>
</tr>
<tr>
<td>Hobbies:</td>

<td><input type="text" name="hobbies" size="30" maxlength="100">
</td>
</tr>
<tr>
<td>Favorite Color:</td>
<td><input type="text" name="favorite_color" size="10" maxlength="30">
</td>
</tr>

<tr>
<td>Favorite Gemstone:</td>
<td><input type="text" name="favorite_gemstone" size="10" maxlength="10">
</td>
</tr>
<tr>
<td>Favorite Food:</td>
<td><input type="text" name="favorite_food" size="10" maxlength="30">

</td>
</tr>
<tr>
<td>Least Favorite Food:</td>
<td><input type="text" name="least_favorite_food" size="10" maxlength="30">
</td>
</tr>
<tr>
<td>Strengths:</td>
<td><input type="text" name="strengths" size="30" maxlength="100">
</td>
</tr>
<tr>
<td>Weaknesses:</td>

<td><input type="text" name="weaknesses" size="30" maxlength="100">
</td>
</tr>
<tr>
<td>Goal:</td>
<td><input type="text" name="goal" size="30" maxlength="100">
</td>
</tr>
<tr>
<td>Mission:</td>
<td><input type="text" name="mission" size="30" maxlength="100">
</td>
</tr>
<tr>
<td>Character Biography:</td>
<td><textarea name="biography" rows=7
cols=46></textarea>
</td>
</tr>
</table>
<p style="text-align: center" class="submit"><input type="submit" value="Create Character" />
<input type="reset" value="Reset" /></p>

</form>

</div>
<?php include("bottomnav.php"winking smiley; ?><!-- FOOTER -->
<!-- FOOTER -->
<div id="footer_wrapper">
<div id="footer">
<p>Sailor Moon and all characters
are<br />
trademarks of Naoko Takeuchi.</p>
<p>Copyright &copy; 2009 Liz Kula. All rights reserved.<br />
A product of <a href="#" target="_blank">Web Designs By Liz</a> systems.</p>
<div id="foot-nav">
<ul>
<li><a href="[validator.w3.org]; target="_blank"><img src="[www.w3.org]; alt="Valid XHTML 1.0 Transitional" height="31" width="88" /></a></li>
<li><a href="[jigsaw.w3.org]; target="_blank"><img class="c2" src="[jigsaw.w3.org]; alt="Valid CSS!" /></a></li>
</ul>
</div>
</div>
</div>
<!-- /FOOTER -->
</body>
</html>

Options: ReplyQuote
Re: Inserting Unwanted Blank Record
Posted by: toumimi (---.117.116-78.rev.gaoland.net)
Date: August 09, 2009 01:12AM

Try in several browsers to see if they cause the double submission.
If yes, search on the net to find solution to avoid this
Else, check elsewhere if you don't submit in the same table (with var without value).

There is no other solution...

Florian

WampServer Patch (Screenshots)
Topic EN : www.wampserver.com
Topic FR : www.wampserver.com

Options: ReplyQuote
Re: Inserting Unwanted Blank Record
Posted by: twilitegxa (---.hsd1.tn.comcast.net)
Date: August 09, 2009 01:32AM

The problem does not occur in Internet Explorer...but does in Firefox. Know any solution for Firefox?

Options: ReplyQuote


Sorry, only registered users may post in this forum.