Wrox Programmer Forums
|
BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 2nd, 2009, 06:44 PM
Registered User
 
Join Date: Sep 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 charedit.php is not poplating the Enemies list

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"){?>
&nbsp;&nbsp;&nbsp;&nbsp;
<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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9 Enemies list won't populate - Help! idlespur BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 September 2nd, 2009 05:59 PM
chap10 - If a hero has no enemies bill_the_cat BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 May 25th, 2008 05:17 AM
Chapter 10 charedit.php issue luke adamis BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 January 1st, 2006 06:28 PM
Chapter 10 - powers and enemies GranDad BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 September 18th, 2005 09:11 PM
Chap 9 - Charedit.php IP076 BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 December 1st, 2004 08:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.