Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > Adobe Web Programming > BOOK: Dreamweaver MX: PHP Web Development
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Dreamweaver MX: PHP Web Development
This is the forum to discuss the Wrox book Dreamweaver MX: PHP Web Development by Gareth Downes-Powell, Tim Green, Bruno Mairlot; ISBN: 9780764543876
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Dreamweaver MX: PHP Web Development section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 30th, 2004, 10:48 AM
Registered User
 
Join Date: Jul 2004
Location: Devonport, , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Hotel Tutorial Dreamweaver MX PHP Web Development

Hi
Has anybody found that there is an error in the code on page 160 of this book. I have the folowing code in my page but it isn't working

if ((isset($HTTP_GET_VARS['bookingID'])) && ($HTTP_GET_VARS['bookingID'] != "") && (isset($HTTP_POST_VARS['bookingID']))) {
  $deleteSQL = sprintf("DELETE FROM bookings WHERE ID=%s",
                       GetSQLValueString($HTTP_GET_VARS['bookingID'], "int"));

  mysql_select_db($database_conn1, $conn1);
  $Result1 = mysql_query($deleteSQL, $conn1) or die(mysql_error());

  $deleteGoTo = "booking_cancelled.php?bookingID=".$HTTP_POST_ VARS['bookingID'].""; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));

The line that I think has the problem is red.

Hope some one can help me.

Lynne

Lynne Maree Ryan
Reply With Quote
  #2 (permalink)  
Old July 30th, 2004, 02:29 PM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, take a look at your code a little more closely. There's a couple problems.

First, your if() statement checks to see if the "bookingID" variable was sent as a GET parameter AND a POST parameter. Odds are it's only passed by one method. You should rewrite your code to only check the method that you expect the parameter to be passed by.

Second, you're trying to print the value passed by POST, but the rest of your code (including the SQL statement) uses the value passed by GET.

Let me be clear: These are two differente variables!


Finally, you should use $_GET and $_POST instead of $HTTP_GET_VARS and $HTTP_POST_VARS. The $HTTP_xxx_VARS versions were deprecated years ago.


Oh yeah, one more thing -- if your site allows the user to submit the bookingID via GET AND POST, then you need to rewrite your code to handle either. You can't handle both at the same time, since you're only cancelling one booking. To handle both would imply cancelling TWO bookings... get it?

Here's a suggestion:

if (isset($_GET['bookingID']))
{
    $bookingID = $_GET['bookingID'];
}
else if (isset($_POST['bookingID']))
{
    $bookingID = $_POST['bookingID'];
}


// now comes your original code,
// except we use $bookingID instead of $HTTP_xxx_VARS['bookingID']

if (isset($bookingID && !empty($bookingID))
{
   $deleteSQL = ...

   ...

   $deleteGoTo = "booking_cancelled.php?bookingID={$bookingID}" ;

   ...
}



Hope this helps!

}

Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #3 (permalink)  
Old July 30th, 2004, 09:18 PM
Registered User
 
Join Date: Jul 2004
Location: Devonport, , Australia.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
Thanks for your reply.
I understand where you are coming from. But tried replacing my code with what you suggested and ended up with an error message. Maybe I replaced the wrong bit :-( I have attached the code again and was wondering if you could make the changes so that I can copy it back in to my page.

Hope this doesn't seem lasy. If I can get the page working then I can study the code and hopefully understand what it is doing

<?php require_once('Connections/conn1.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

if ((isset($HTTP_GET_VARS['bookingID'])) && ($HTTP_GET_VARS['bookingID'] != "") && (isset($HTTP_POST_VARS['bookingID']))) {
  $deleteSQL = sprintf("DELETE FROM bookings WHERE ID=%s",
                       GetSQLValueString($HTTP_GET_VARS['bookingID'], "int"));

  mysql_select_db($database_conn1, $conn1);
  $Result1 = mysql_query($deleteSQL, $conn1) or die(mysql_error());

  $deleteGoTo = "booking_cancelled.php?bookingID=".$HTTP_POST_ VARS['bookingID']."";
  if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}
?>

Once again thanks for helping me.




Lynne Maree Ryan
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning PHP, Apache, MySQL® Web Development beolay2k BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 July 29th, 2008 08:32 PM
Beginning PHP, Apache, MySQL Web Development rich_m BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 January 7th, 2007 01:16 PM
new to Dreamweaver MX ad04jackal Dreamweaver (all versions) 2 August 10th, 2004 02:20 PM



All times are GMT -4. The time now is 11:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.