Jump to content

Query is inserting 2 fields instead of one


Hartley

Recommended Posts

In the following script that I wrote (used to work, but for some reason when I made a change it did some funny stuff), for some reason, 2 rows appear instead of one:

The first one is the regular row exactly as it should be, the second is completely empty with the exception of the default values. I can't figure out why the second one is appearing...

[code]$rname = htmlspecialchars($_POST['rname']);
$age = htmlspecialchars($_POST['age']);
$email = htmlspecialchars($_POST['email']);
$appusername = htmlspecialchars($_POST['appusername']);
$profession = htmlspecialchars($_POST['profession']);
$whyjoin = htmlspecialchars($_POST['whyjoin']);
$whyjoin = nl2br($whyjoin);
$role = htmlspecialchars($_POST['role']);
$role = nl2br($role);
$responsibility = htmlspecialchars($_POST['responsibility']);
$responsibility = nl2br($responsibility);
$friendships = htmlspecialchars($_POST['friendships']);
$friendships = nl2br($friendships);
$hear = htmlspecialchars($_POST['hear']);
$hear = nl2br($hear);
$cname = htmlspecialchars($_POST['cname']);
$class = htmlspecialchars($_POST['class']);
$talent = htmlspecialchars($_POST['talent']);
$daily = htmlspecialchars($_POST['daily']);
$prof1 = htmlspecialchars($_POST['prof1']);
$prof2 = htmlspecialchars($_POST['prof2']);
$previous = htmlspecialchars($_POST['previous']);
$previous = nl2br($previous);
$references = htmlspecialchars($_POST['references']);
$references = nl2br($references);
$oldguilds = htmlspecialchars($_POST['oldguilds']);
$oldguilds = nl2br($oldguilds);
$whyyou = htmlspecialchars($_POST['whyyou']);
$whyyou = nl2br($whyyou);
$raider = htmlspecialchars($_POST['raider']);
$raider = nl2br($raider);
$spec_gameplay = htmlspecialchars($_POST['spec_gameplay']);
$spec_gameplay = nl2br($spec_gameplay);
$yourgoals = htmlspecialchars($_POST['yourgoals']);
$yourgoals = nl2br($yourgoals);
$ourgoals = htmlspecialchars($_POST['ourgoals']);
$ourgoals = nl2br($ourgoals);
$anythingelse = htmlspecialchars($_POST['anythingelse']);
$anythingelse = nl2br($anythingelse);
$software = htmlspecialchars($_POST['software']);
$behavior_agree = htmlspecialchars($_POST['behavior_agree']);

$hostname="----";
$username="----";
$password="----";
$dbname="----";

$conn = mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);

mysql_query("INSERT INTO $faction (appid, rname, age, email, username, profession, whyjoin, role, responsibility, friendships, hear, cname, class, talent, daily, prof1, prof2, previous, igreferences, oldguilds, whyyou, raider, spec_gameplay, yourgoals, ourgoals, anythingelse, software, behavior_agree) VALUES ('', '$rname', '$age', '$email', '$appusername', '$profession', '$whyjoin', '$role', '$responsibility', '$friendships', '$hear', '$cname', '$class', '$talent', '$daily', '$prof1', '$prof2', '$previous', '$references', '$oldguilds', '$whyyou', '$raider', '$spec_gameplay', '$yourgoals', '$ourgoals', '$anythingelse', '$software', '$behavior_agree')") or die(mysql_error());

mysql_close($conn);[/code]
Link to comment
Share on other sites

if appid is an auto-increment column, do not include it in the query.

To make sure that it only inserted once, put limit 1 as a guard.  Aside of that I don't see any problem with the query that caused it to insert twice.

Maybe you have a loop somewhere that do this for you?

Link to comment
Share on other sites

I do have another database query earlier, is there anything in the chunk of code that may cause problems?

[code]<?php

if (empty($_COOKIE['sbbuserid'])) {
  $pmbox = " <!-- login form -->
<form action=\"http://www.sedition-gaming.com/community/login.php?do=login\" method=\"post\" style=\"display:inline\" onsubmit=\"md5hash(vb_login_password, vb_login_md5password, vb_login_md5password_utf, $show[nopasswordempty])\">
<script type=\"text/javascript\" src=\"clientscript/vbulletin_md5.js?v=$vboptions[simpleversion]\"></script>
<table cellpadding=\"0\" cellspacing=\"$stylevar[formspacer]\" border=\"0\">
<tr>
<td class=\"smallfont\"><label for=\"navbar_username\">User</label></td>
<td><input type=\"text\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_username\" id=\"navbar_username\" size=\"10\" accesskey=\"u\" tabindex=\"101\" value=\"Username\" style=\"display:inline\" onfocus=\"if (this.value == 'Username') this.value = '';\" /></td>
<td class=\"smallfont\" colspan=\"2\" nowrap=\"nowrap\"><input type=\"checkbox\" name=\"cookieuser\" value=\"1\" tabindex=\"103\" id=\"cb_cookieuser_navbar\" style=\"display:inline\" accesskey=\"c\" />Remember Me</td>
</tr>
<tr>
<td class=\"smallfont\">Pass</td>
<td><input type=\"password\" style=\"display:inline\" class=\"bginput\" style=\"font-size: 11px\" name=\"vb_login_password\" id=\"navbar_password\" size=\"10\" tabindex=\"102\" /></td>
<td><input type=\"submit\" class=\"button\" value=\"Log in\" tabindex=\"104\" title=\"Enter username to login\" accesskey=\"s\" /></td>
</tr>
</table>
<input type=\"hidden\" name=\"s\" value=\"$session[sessionhash]\" />
<input type=\"hidden\" name=\"do\" value=\"login\" />
<input type=\"hidden\" name=\"vb_login_md5password\" />
<input type=\"hidden\" name=\"vb_login_md5password_utf\" />
</form>
<!-- / login form -->";

  $register = "<td class=\"silverbar\"><a href=\"http://www.sedition-gaming.com/community/register.php\" rel=\"nofollow\">Register</a></td>";
} else {

$dbhost = '----';
$dbuser = '----';
$dbpass = '----';
$dbname = '----';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

$pminbox = "SELECT pmtotal, pmunread, userid, username, salt, lastvisit FROM user WHERE userid = " .$_COOKIE['sbbuserid'];
$pmquery = mysql_query($pminbox);

while($pmstatus = mysql_fetch_assoc($pmquery))
{
  $unread = "{$pmstatus['pmunread']}";
  $total = "{$pmstatus['pmtotal']}";
  $userid = "{$pmstatus['userid']}";
  $username = "{$pmstatus['username']}";
  $salt = "{$pmstatus['salt']}";
  $lastvisit = "{$pmstatus['lastvisit']}";

if (!$unread || $unread == "0") {

$unread = $unread; }

else {

$unread = "<strong>$unread</strong>"; }

define('COOKIE_SALT', 'VBFD762FE8');

$logouthash = md5($userid . $salt . COOKIE_SALT);

  $usercp = "<td class=\"silverbar\"><a href=\"http://www.sedition-gaming.com/community/usercp.php$session[sessionurl_q]\">Edit Profile</a></td>";
  $logout = "<td class=\"silverbar\"><a href=\"http://www.sedition-gaming.com/community/login.php?do=logout&amp;logouthash=$logouthash\" onclick=\"return log_out()\">Log Out</a></td>";

}

$orientation = "SELECT userid, usergroupid, username, orientation, popupstat FROM user WHERE userid = " .$_COOKIE['sbbuserid'];
$orientationquery = mysql_query($orientation);

while($orstatus = mysql_fetch_assoc($orientationquery))
{
  $userid = "{$orstatus['userid']}";
  $usergroupid = "{$orstatus['usergroupid']}";
  $username = "{$orstatus['username']}";
  $orientation = "{$orstatus['orientation']}";
  $popup = "{$orstatus['popupstat']}";

if (!$usergroupid || $usergroupid == "6") {

if (!$orientation || $orientation == "0") {

$orientationstatus = "<table class=\"tborder\" cellpadding=\"0\" cellspacing=\"1\" border=\"0\" width=\"558\">
<tr>
<td class=\"newspost-head-red\"><a href=\"http://www.sedition-gaming.com/orientation.php?step=1\">Welcome to Sedition Gaming!</a></td></tr>
<tr>
<td class=\"newspost-body\">
&nbsp;&nbsp;Hello, and congratulations on becoming a member of Sedition, a global gaming community. All members are required to go through a brief orientation to familiarize yourselves with some of our guild's structure and policies. The entire process should take approximately 15 minutes to complete and is required within 7 days of attaining membership status. <a href=\"http://www.sedition-gaming.com/orientation.php?step=1\" class=\"darkredlink\">Click here</a> to begin!
</td></tr></table>

<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
  <tr>
  <td height=\"5\"><img src=\"images/site/clear.gif\" width=\"1\" height=\"1\" border=\"0\" alt=\"Spacer\" /></td>
  </tr>
</table>";

if (!$popup || $popup == "0") {

$popupquery = "UPDATE user SET popupstat='1' WHERE userid = " .$vbulletin->userinfo['userid'];
$popupquery2 = mysql_query($popupquery);

$orientationpopup = "<script type=\"text/javascript\">
<!--
// script to show new private message popup

if (confirm(\"Congrats on becoming a member of Sedition!\\n\\n**Orientation is required within 7 days.**\\n\\nClick OK to go to first step, or cancel to hide this prompt.\\n\\nA message will be at the top of the forum until you complete orientation.\"))
{
// Output when OK is clicked
if (confirm(\"Open orientation in a new window?\\n\\n(Press cancel to open in the current window.)\"))
{
var winobj = window.open(\"http://www.sedition-gaming.com/orientation.php?step=1\", \"orientation\", \"statusbar=yes,menubar=yes,scrollbars=yes,toolbar=yes,location=yes,directories=yes,resizable=yes,top=50,left=50\");
if (winobj == null)
{
alert(\"Unable to open a new browser window,\\n This might be due to a 'popup blocker'\");
}
}
else
{
window.location = \"http://www.sedition-gaming.com/orientation.php?step=1\";
}
}

// end pm popup script
//-->
</script>";

}

}

}

}

$currenttime = time();
$timediff = $currenttime - $lastvisit;

if ($timediff < 0) {
$timeago = "1 minute ago"; }

elseif ($timediff == 1) {
$timeago = "1 second ago"; }

elseif ($timediff >= 2 && $timediff < 60) {
$timediff = $timediff;
$timeago = "$timediff seconds ago"; }

elseif ($timediff >= 60 && $timediff < 120) {
$timeago = "1 minute ago"; }

elseif ($timediff >= 120 && $timediff < 3600) {
$timediff = floor($timediff / 60);
$timeago = "$timediff minutes ago"; }

elseif ($timediff >= 3600 && $timediff < 7200) {
$timeago = "1 hour ago"; }

elseif ($timediff >= 7200 && $timediff < 86400) {
$timediff = floor($timediff / 3660);
$timeago = "$timediff hours ago"; }

elseif ($timediff >= 86400 && $timediff < 172800) {
$timeago = "1 day ago"; }

elseif ($timediff >= 172800 && $timediff < 604800) {
$timediff = floor($timediff / 86400);
$timeago = "$timediff days ago"; }

elseif ($timediff >= 604800 && $timediff < 1209600) {
$timeago = "1 week ago"; }

elseif ($timediff >= 1209600 && $timediff < 2592000) {
$timediff = floor($timediff / 604800);
$timeago = "$timediff weeks ago"; }

elseif ($timediff >= 2592000 && $timediff < 5184000) {
$timeago = "1 month ago"; }

elseif ($timediff >= 5184000 && $timediff < 31104000) {
$timediff = floor($timediff / 2592000);
$timeago = "$timediff months ago"; }

elseif ($timediff >= 31104000 && $timediff < 62208000) {
$timeago = "1 year ago"; }

elseif ($timediff >= 62208000) {
$timediff = floor($timediff / 31104000);
$timeago = "$timediff years ago"; }

mysql_close($conn);

  $pmbox = "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" height=\"42\"><tr><td valign=\"bottom\"><strong>Welcome, $username!</strong></td></tr>
<tr><td valign=\"bottom\">You last visited: $timeago.</td></tr>
<tr><td valign=\"bottom\"><a href=\"http://www.sedition-gaming.com/community/private.php\">Private Messages</a>: Unread $unread, Total $total.</tr></td></if></table>";
}

if (empty($_GET['p'])) {
  $p = 'latest';
} else {
  $p = $_GET['p'];
}

?>[/code]

Thanks again for your time, I've been up 30 hours working on this and it's hard to find everything.
Link to comment
Share on other sites

Another thing I noted: I added a timestamp, and the second field (the empty one) adds itself one second after the first. I removed the above code and it still showed the same error.

I have another small script that updates some other stuff in the database, and oddly enough, that one is doing a very similar thing and resetting any updates I make. I'll have to delve into the code and see where it could be going wrong.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.