
Has anyone had this problem of the enemies list not being populated when you add or edit a character? The first character I added worked perfect and when I went back to edit that character it showed his enemy like it should. Since then each character I add it only gives me the first to enemies, a good guy and a bad guy. I have entered enemy id's by hand and it still does not show them. Help!
Here is my charedit.php code:
<?php
require('config.php');
$char = $_GET['c'];
if ($char == '' || !is_numeric($char)) $char='0';
$subtype = "Create";
$subhead = "Please enter character data and click '$subtype
Character.'";
$tablebg = '#EEEEFF';
$conn = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS)
or die('Could not connect to MySQL database. ' . mysql_error());
mysql_select_db(SQL_DB,$conn);
$sql = "SELECT id, power FROM char_power";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
While ($row = mysql_fetch_assoc($result)) {
$pwrlist[$row['id']] = $row['power'];
}
}
$sql = "SELECT id, alias FROM char_main WHERE id != $char";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
$charlist[$row['id']] = $row['alias'];
}
if ($char != '0') {
$sql = "SELECT c.alias, c.real_name AS name, c.align, l.lair_addr
AS address, z.city, z.state, z.id AS zip FROM char_main c,
char_lair l, char_zipcode z WHERE z.id = l.zip_id AND
c.lair_id = l.id AND c.id = $char";
$result = mysql_query($sql) or die(mysql_error());
$ch = mysql_fetch_assoc($result);
if (is_array($ch)) {
$subtype = "Update";
$tablebg = '#EEFFEE';
$subhead = "Edit data for <i>" . $ch['alias'] . "</i> and click
'$subtype Character.'";
$sql = "SELECT p.id FROM char_main c JOIN char_power p
JOIN char_power_link pk ON c.id = pk.char_id
AND p.id = pk.power_id WHERE c.id = $char";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
While ($row = mysql_fetch_assoc($result)) {
$powers[$row['id']] = 'selected';
}
}
// get list of character's enemies
$sql = "SELECT n.id FROM char_main c JOIN char_good_bad_link gb
JOIN char_main n ON (c.id = gb.good_id AND n.id = gb.bad_id)
OR (n.id = gb.good_id AND c.id = gb.bad_id) WHERE
c.id = $char";
$result = mysql_query($sql) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
While ($row = mysql_fetch_assoc($result)) {
$enemies[$row['id']] = 'selected';
}
}
}
}
?>
<html>
<head>
<title>Character Editor</title>
<!-- <link rel="stylesheet" type="text/css" href="css/styles.css" />
<link rel="icon" type="image/png" href="favicon.png"> -->
</head>
<body>
<div align="center">
<h1><img src='images/cba_tiny.gif' hspace='10'><br />Comic Book Appreciation</h1><br />
<h3><?php echo $subhead;?></h3>
<form action='char_transact.php' name='theform' method='post'>
<table align="center" border='0' cellpadding='15' bgcolor='<?php echo $tablebg;?>'>
<tr>
<td>Character Name:</td>
<td><input type='text' name='alias' size='41'
value='<?php echo $ch['alias'];?>' onfocus='this.select();'>
</td>
</tr>
<tr>
<td>Real Name:</td>
<td><input type='text' name='name' size='41'
value='<?php echo $ch['name'];?>' onfocus='this.select;'>
</td>
</tr>
<tr>
<td>Powers:<br /><font size=2 color='#990000'>
(Ctrl-click to<br />select multiple<br />powers)</font>
</td>
<td>
<select multiple='multiple' name='powers[]' size='4'>
<?php
foreach ($pwrlist as $key => $value) {
echo "<option value='$key' " . $powers[$key] .
">$value</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td>Lair Location:<br /><font size=2 color='#990000'>
(address,<br />city, state, zip)</font>
</td>
<td><input type='text' name='address' size='41'
value='<?php echo $ch['address'];?>'
><br />
<input type='text' name='city' value='<?php echo $ch['city'];?>'
>
<input type='text' name='state' size='2'
value='<?php echo $ch['state'];?>' >
<input type='text' name='zip' size='10'
value='<?php echo $ch['zip'];?>' >
</td>
</tr>
<tr>
<td>Alignment:</td>
<td><input type='radio' name='align' value='good'<?php
echo($ch['align']=='good' ? ' checked="checked"' : '');?>>
good<br />
<input type='radio' name='align' value='evil'<?php
echo($ch['align']=='evil' ? ' checked="checked"' : '');?>>
evil
</td>
</tr>
<?php if (is_array($charlist)) { ?>
<tr>
<td>Enemies:<br /><font size=2 color='#990000'>
(Ctrl-click to<br />select multiple<br />enemies)</font>
</td>
<td>
<select multiple='multiple' name='enemies[]' size='4'>";
<?php
foreach ($charlist as $key => $value) {
echo "<option value='$key' ".$enemies[$key].">$value</option>\n";
}
?>
</select>
</td>
</tr>
<?php }?>
<tr>
<td colspan=2>
<input type='submit' name='action'
value='<?php echo $subtype;?> Character'>
<input type="reset">
<?php if ($subtype == "Update"){?>
<input type='submit' name='action' value='Delete Character'>
<?php }?>
</td>
</tr>
</table>
<input type='hidden' name='cid' value='<?php echo $char;?>'>
</form>
<a href='charlist.php'>Return to Home Page</a>
</div>
</body>
</html>
This code is exactly the same as the book and the download. Any help you can offer will be greatly appreciated.
Idlespur
