...

View Full Version : Not updating database



CoolAsCarlito
03-17-2010, 08:50 PM
However its not posting anything to the DB now and don't know why.



case 3:
echo $e;
$query = "SELECT s.hometown, s.height, s.weight,
h.kowtitles, h.kowawards,
w.nicknames, w.finisher, w.setup, w.music
FROM `efed_bio_singles` AS s,
`efed_bio_history` AS h,
`efed_bio_wrestling` AS w
WHERE s.bio_id = '$defaultcharacterid' AND
h.bio_id = '$defaultcharacterid' AND
w.bio_id = '$defaultcharacterid'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$height = mysql_real_escape_string($height);
?>
<h1 class=backstage>Character Management</h1><br />
<h2 class=backstage><?php echo $defaultcharactername; ?> - Personal</h2><br />
<form name="editcharacter" method="post">
<input type="hidden" name="action" value="character" />
<table width="100%" class="table2">
<tr>
<td width=120 class=rowheading>Hometown:</td><td class=row3>
<input type=text name="hometown" class=fieldtext490 value="<?php echo $row['hometown']; ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>Height:</td><td class=row3>
<input type=text name="height" class=fieldtext40 value="<?php echo htmlspecialchars($row['height']); ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>Weight:</td><td class=row3>
<input type=text name="weight" class=fieldtext80 value="<?php echo $row['weight']; ?>"></td>
</tr>
</table><br />
<h2 class=backstage>KOW Related</h2><br />
<table width="100%" class="table2">
<tr>
<td width=120 class=rowheading>KOW Titles:</td><td class=row3>
<input type=text name="kowtitles" class=fieldtext490 value="<?php echo $row['kowtitles']; ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>KOW Awards:</td><td class=row3>
<input type=text name="kowawards" class=fieldtext490 value="<?php echo $row['kowawards']; ?>"></td>
</tr>
</table><br />
<h2 class=backstage>Wrestling</h2><br />
<table width="100%" class="table2">
<tr>
<td width=120 class=rowheading>Nicknames:</td><td class=row3>
<input type=text name="nicknames" class=fieldtext490 value="<?php echo $row['nicknames']; ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>Manager:</td><td class=row3>
<select name="managerid" class=dropdown>
<option value="0">- Select -</option>
<?php
$query = 'SELECT charactername,id FROM `efed_bio` WHERE `style_id`= 3';
$result = mysql_query ( $query );
while ( $manager_row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$manager_row['id']."\" ";
if($manager_row['id'] == $row['manager_id']) {
print " SELECTED";
}
print ">".$manager_row['charactername']."</option>\r";
}
?>
</select></td>
</tr>
<tr>
<td width=120 class=rowheading>Finisher Move:</td><td class=row3>
<input type=text name="finisher" class=fieldtext490 value="<?php echo $row['finisher']; ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>Setup Move:</td><td class=row3>
<input type=text name="setup" class=fieldtext490 value="<?php echo $row['setup']; ?>"></td>
</tr>
<tr>
<td width=120 class=rowheading>Entrance Music:</td><td class=row3>
<input type=text name="music" class=fieldtext490 value="<?php echo $row['music']; ?>"></td>
</tr>
</table><br />
<input type="hidden" name="defaultcharacterid" value="<?php echo $row['defaultcharacterid']; ?>">
<input type="hidden" name="editted2" value="true">
<input type=submit value="Update Bio" class=button></form><br />
<?php
returnmain();
break;


Here's the query I"m running with it.



if ((!empty($_POST['editted2']))) {
$kowtitles = mysql_real_escape_string($_POST['kowtitles']);
$kowawards = mysql_real_escape_string($_POST['kowawards']);
$height = mysql_real_escape_string($_POST['height']);
$weight = mysql_real_escape_string($_POST['weight']);
$hometown = mysql_real_escape_string($_POST['hometown']);
$managerid = mysql_real_escape_string($_POST['managerid']);
$nicknames = mysql_real_escape_string($_POST['nicknames']);
$finisher = mysql_real_escape_string($_POST['finisher']);
$setup = mysql_real_escape_string($_POST['setup']);
$music = mysql_real_escape_string($_POST['music']);
$defaultcharacterid = mysql_real_escape_string($_POST['defaultcharacterid']);
$query = "UPDATE `efed_bio_history` SET `kowtitles` = '".$kowtitles."', `kowawards` = '".$kowawards."' WHERE `bio_id` = '".$defaultcharacterid."'";
if(!mysql_query($query)){ echo mysql_error() . "<br />" . $query;}
echo $query;
$query2 = "UPDATE `efed_bio_singles` SET `height` = '".$height."', `hometown` = '".$hometown."', `weight` = '".$weight."' WHERE `bio_id` = '".$defaultcharacterid."'";
if(!mysql_query($query2)){ echo mysql_error() . "<br />" . $query2;}
echo $query2;
$query3 = "UPDATE `efed_bio_wrestling` SET `manager_id` = '".$managerid."', `nicknames` = '".$nicknames."', `finisher` = '".$finisher."', `setup` = '".$setup."', `music` = '".$music."' WHERE `bio_id` = '".$defaultcharacterid."'";
if(!mysql_query($query3)){ echo mysql_error() . "<br />" . $query3;}
echo $query3;
}


With the echoed query it says :

UPDATE `efed_bio_history` SET `kowtitles` = 'Testing', `kowawards` = 'Testing' WHERE `bio_id` = ''UPDATE `efed_bio_singles` SET `height` = '5\\\'4\\\"', `hometown` = 'Tokoyo, Japan', `weight` = '145 lbs.' WHERE `bio_id` = ''UPDATE `efed_bio_wrestling` SET `manager_id` = '0', `nicknames` = 'Testing', `finisher` = 'Testing', `setup` = 'testing', `music` = 'testing' WHERE `bio_id` = ''

Which means something is wrong with it getting the defaultcharacterid but I passed it correctly with the hidden field.

Fou-Lu
03-17-2010, 09:02 PM
'Cept defaultcharacterid isn't in you're $row. Check you're query again, there is no field name / alias in use to map a column to that name. I do see a standard variable named $defaultcharacterid, but I don't know where it comes from so I assume it to be valid.

tomws
03-17-2010, 09:09 PM
Nothing "wrong" with defaultcharacterid except that it's apparently empty, so the database won't update since there's no bio_id field that's empty.

Before you submit the form, look at the HTML and see what value is listed for that hidden input. If nothing, the problem is on the form page and your initial query there.

CoolAsCarlito
03-17-2010, 09:09 PM
I knew this was going to be an issue. The defaultcharacterid is coming from the id of the person that is logged in. Can I use:

$defaultcharacterid = mysql_real_escape_string($defaultcharacterid);

and

<input type="hidden" name="defaultcharacterid" value="<?php echo $defaultcharacterid; ?>">

CoolAsCarlito
03-17-2010, 09:28 PM
Somehow I fixed. Don't know how but I did.

Fou-Lu
03-17-2010, 09:31 PM
I knew this was going to be an issue. The defaultcharacterid is coming from the id of the person that is logged in. Can I use:

$defaultcharacterid = mysql_real_escape_string($defaultcharacterid);

and

<input type="hidden" name="defaultcharacterid" value="<?php echo $defaultcharacterid; ?>">

You sure can, there is no issue with using a known variable. My original post was in regards to you're query itself which did not include the 'defaultcharacterid' within it - this is why it passed over an empty value.


I think we're all looking at different blocks. You cannot just use the $defaultcharacterid within the SECOND block of code you have posted, but you can use it in the first (though you probably don't need to use an escape sequence on it). The problem is the FIRST block of code where it is not actually passing a value for the hidden defaultcharacterid. That one needs to either have the query edited or the $defaultcharacterid provided at this level of the scope given to it as its value.

Oh nvm, you've corrected the issue I see.

CoolAsCarlito
03-17-2010, 09:42 PM
One more issue though:



<tr>
<td width=120 class=rowheading>Manager:</td><td class=row3>
<select name="managerid" class=dropdown>
<option value="0">- Select -</option>
<?php
$query = 'SELECT charactername,id FROM `efed_bio` WHERE `style_id`= 3';
$result = mysql_query ( $query );
while ( $manager_row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$manager_row['id']."\" ";
if($manager_row['id'] == $row['manager_id']) {
print " SELECTED";
}
print ">".$manager_row['charactername']."</option>\r";
}
?>
</select></td>


Its still in continuance with code above. I am trying to have pre-select the existing value from the database.

I have the query that's in there now but I need to include in there somehow with the table efed_bio_singles because a field in that table is called manager_id and that is equal to efed_bio field called id and then get the charactername from there.

Fou-Lu
03-17-2010, 09:59 PM
Looks to me like you're initial query there you can just add an s.manager_id. Compare that later from the $row['manager_id']. Unfortunately I don't know you're table structures, so I can't be 100% certain thats where it is, but it sounds to me like that will do it.

CoolAsCarlito
03-17-2010, 10:07 PM
Table structure
efed_bio-id, charactername,style_id
efed_bio_wrestling-bio_id,manager_id

Updated:



<tr>
<td width=120 class=rowheading>Manager:</td><td class=row3>
<select name="managerid" class=dropdown>
<option value="0">- Select -</option>
<?php
$query = 'SELECT bio.charactername,bio.id,w.manager_id FROM efed_bio AS bio, efed_bio_wrestling AS w WHERE bio.style_id= 3';
$result = mysql_query ( $query );
while ( $manager_row = mysql_fetch_assoc ( $result ) )
{
print "<option value=\"".$manager_row['id']."\" ";
if($manager_row['id'] == $row['manager_id']) {
print " SELECTED";
}
print ">".$manager_row['charactername']."</option>\r";
}
?>
</select></td>
</tr>

Fou-Lu
03-17-2010, 10:17 PM
Alter you're initial query in the case there to add w.manager_id. That will then be available for use with the comparison inside of the selection menu.

CoolAsCarlito
03-17-2010, 10:24 PM
Its already there in there.

Fou-Lu
03-17-2010, 10:46 PM
I don't see it in there:


SELECT s.hometown, s.height, s.weight,
h.kowtitles, h.kowawards,
w.nicknames, w.finisher, w.setup, w.music

CoolAsCarlito
03-17-2010, 11:00 PM
Thank you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum