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 December 1st, 2004, 12:45 AM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IP076
Default Chap 9 - Charedit.php

Hey all,

Line 4 on this page reads: $char = $_GET['c'];

I'm a little confused as to what 'c' is and where it comes from.

My limited understand would think that there has to be a form somewhere with an action="get" setting and an input device name 'c'.

I'm trying to build a contacts database, and I'd like to use this set up because it automatically figures if you are trying to update or create a new entry. I'm just a little confused on what its doing there on line 4, and I haven't found a good explanation of it yet.

Thank you!

 
Old December 1st, 2004, 12:56 AM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IP076
Default

Actually,

I'm trying to have it set up where a person logs in to my site, then he can enter all his information.

I would like it so that the next time he logs in and opens the page, it auto loads with his preloaded information in the form, so as to edit the information.

Do you think using the Comic database examples are the best, or is there another way?

I was thinking of running an if statement that would determine if the user has an entry or not, and then either loads a black form, or loads the already entered values. Like I said, I'm new to it all, and just looking for opinions.

Thank you!

 
Old December 1st, 2004, 12:23 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I read the book quite a while back. Could u please post the code.
FYI: The 'c' could be passed on the url like: page.php?c=value

Christian
 
Old December 1st, 2004, 08:17 PM
Authorized User
 
Join Date: Nov 2004
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to IP076
Default

<?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>
</head>
<body>
<img src='CBA_Tiny.gif' align='left' hspace='10'>
<h1>Comic Book<br />Appreciation</h1><br />
<h3><?php echo $subhead;?></h3>

<form action='char_transact.php' name='theform' method='post'>
<table 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'];?>'
 >
  </td>
 </tr>
 <tr>
  <td>Real Name:</td>
  <td><input type='text' name='name' size='41'
   value='<?php echo $ch['name'];?>'
 >
  </td>
 </tr>
 <tr>
  <td>Powers:<br />
   (Ctrl-click to<br />select multiple<br />powers)
  </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 />
   (address,<br />city, state, zip)
  </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 />
   (Ctrl-click to<br />select multiple<br />enemies)
  </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>
</body>
</html>


There's the code, looking thru the other pages, I don't see that the value would be passed via the url.

Thanks






Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Pro Chap 3 wozza1664 Pro PHP 1 June 23rd, 2008 03:05 PM
Pro PHP Chap 15 kgmcmillen Pro PHP 1 April 20th, 2006 02:38 PM
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
chap. 12 -cmstables.php niy BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 3 January 12th, 2005 02:36 PM
Chap. 11 - Try It Out, Session Tracking with PHP Tachyon BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 5 June 17th, 2004 02:02 PM





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