Jump to content

Recommended Posts

We want to look at showCart.php don't we?  Which page is having the problem, showCart or showProduct?

 

showcart is displaying the error but its coming from showproduct

 

<?php

  // The shopping cart needs sessions, so start one

  session_start();

 

  $productid = $_GET['productid'];

 

 

  // get this product out of database

  $product = get_product_details($productid);

  do_html_header($product['name']);

  display_product_details($product);

 

  // set url for "continue button"

  $target = 'index.php';

  if($product['catid'])

  {

    $target = 'showCat.php?catid='.$product['catid'];

  }

  // if logged in as admin, show edit product links

  //if(check_admin_user())

  {

    //display_button("edit_book_form.php?productid=$productid", edit-item, 'Edit Item');

    //display_button('admin.php', 'admin-menu', 'Admin Menu');

    //display_button($target, 'continue', 'Continue');

  }

  //else

  {

    display_form_button( 'add-to-cart', 'Add '.$product['name'].' To My Shopping Cart');

    ?> <br /> <?php

    display_button($target, 'continue-shopping', 'continue Shopping');

  }

 

  do_html_footer();

 

function get_product_details($productid)

{

  // query database for all details for a particular product

  if (!$productid || $productid=='')

    return false;

 

    @ $db = mysql_connect('');

    mysql_select_db('');

 

  $query = "select * from products where productid='$productid'";

  $result = mysql_query($query);

  if (!$result)

    return false;

  $result = mysql_fetch_assoc($result);

  return $result;

}

 

function display_product_details($product)

{

  // display all details about this product

  if (is_array($product))

  {

    echo '<table><tr>';

    //display the picture if there is one

    if (@file_exists($product['productid'].'.jpg'))

    {

$myproduct = GetImageSize(($product['productid'].'.jpg'));

 

echo '<img src='.($product['productid']).'.jpg border= '.img_resize($myproduct[0], 

      $myproduct[1], 450).' />';     

 

    }

 

    echo '<td><ul>';

    echo '</li><li><b>Price:</b> £';

    echo number_format($product['price'], 2);

    echo '</li><li><b>Colour:</b> ';

    echo $product['colour'];

    echo '<li><b>Fabric:</b> ';

    echo $product['fabric'];

    echo '</li></ul></td></tr></table>';?>

  <form action="showCart.php" method="post">

    Select size:

    <select name="size">

      <option value=""></option>

      <option value="6">6</option>

      <option value="8">8</option>

      <option value="10">10</option>

      <option value="12">12</option>

        <option value="14">14</option>

    </select> <br/>

Select quantity:

    <select name="quantity">

      <option value="1">1</option>

      <option value="2">2</option>

      <option value="3">3</option>

      <option value="4">4</option>

      <option value="5">5</option>

    </select>

 

<?php

  }

  else

    echo 'The details of this book cannot be displayed at this time.';

  echo '<hr />';

}

 

 

 

 

function do_html_footer()

{

?>

  </form>

  </body>

  </html>

<?php

}

 

function do_html_url($url, $name)

{

?>

  <a href="<?php echo $url; ?>"><?php echo $name; ?></a><br />

<?php

}

 

function do_html_header($title = '')

{

  // print an HTML header

 

  // declare the session variables we want access to inside the function 

  if(!$_SESSION['items']) $_SESSION['items'] = '0';

  if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';

?>

  <html>

  <head>

    <title><?php echo $title; ?></title>

    <style>

      h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red; margin = 6px }

      body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

      li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

      hr { color: #FF0000; width=70%; text-align=center}

      a { color: #000000 }

    </style>

  </head>

  <body>

  <table width='100%' border=0 cellspacing = 0 bgcolor='#cccccc'>

  <tr>

  <td rowspan = 2>

  <a href = 'index.php'><img src='Collections.jpg' alt='Collections' border=0

      align='left' valign='bottom' height = 55 width = 325></a>

  </td>

  <td align = 'right' valign = 'bottom'>

  <?php if(isset($_SESSION['admin_user']))

      echo ' ';

    else

      echo 'Total Items = '.$_SESSION['items'];

  ?>

  </td>

  <td align = 'right' rowspan = 2 width = 135>

  <?php //if(isset($_SESSION['admin_user']))

      //display_button('logout.php', 'log-out', 'Log Out');

    //else

      display_button('showCart.php', 'view-cart', 'View Cart');

  ?>

  </tr>

  <tr>

  <td align = right valign = top>

  <?php if(isset($_SESSION['admin_user']))

      echo ' ';

    else

      echo 'Total Price = £'.number_format($_SESSION['total_price'],2);

  ?>

  </td>

  </tr>

  </table>

<?php

  if($title)

    do_html_heading($title);

}

 

function do_html_heading($title)

{

?>

  <h3><?php echo $title; ?></h3>

<?php

}

 

 

function img_resize($width, $height, $target)

{

 

  if ($width > $height)

  {

    $percentage = ($target / $width);

  }

  else

  {

    $percentage = ($target / $height);

  }

 

  $width = round($width * $percentage);

  $height = round($height * $percentage);

 

  return "width=\"$width\" height=\"$height\"";

}

 

function display_button($target, $image, $alt)

{

  echo "<center><a href=\"$target\"><img src=\"$image".".gif\"

          alt=\"$alt\" border=0 height =32 width = 100></a></center>";

}

 

function display_form_button($image, $alt)

{

  echo "<center><input type =  image src=\"$image".".gif\"

          alt=\"$alt\" border=0 height = 32 width = 100></center>";

}

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429603
Share on other sites

Post showProduct too.

 

<?php

  // The shopping cart needs sessions, so start one

  session_start();

 

  $productid = $_GET['productid'];

 

 

  // get this product out of database

  $product = get_product_details($productid);

  do_html_header($product['name']);

  display_product_details($product);

 

  // set url for "continue button"

  $target = 'index.php';

  if($product['catid'])

  {

    $target = 'showCat.php?catid='.$product['catid'];

  }

  // if logged in as admin, show edit product links

  //if(check_admin_user())

  {

    //display_button("edit_book_form.php?productid=$productid", edit-item, 'Edit Item');

    //display_button('admin.php', 'admin-menu', 'Admin Menu');

    //display_button($target, 'continue', 'Continue');

  }

  //else

  {

    display_form_button( 'add-to-cart', 'Add '.$product['name'].' To My Shopping Cart');

    ?> <br /> <?php

    display_button($target, 'continue-shopping', 'continue Shopping');

  }

 

  do_html_footer();

 

function get_product_details($productid)

{

  // query database for all details for a particular product

  if (!$productid || $productid=='')

    return false;

 

    @ $db = mysql_connect('mysql12.streamline.net', 'collection', 's126655');

    mysql_select_db('collection');

 

  $query = "select * from products where productid='$productid'";

  $result = mysql_query($query);

  if (!$result)

    return false;

  $result = mysql_fetch_assoc($result);

  return $result;

}

 

function display_product_details($product)

{

  // display all details about this product

  if (is_array($product))

  {

    echo '<table><tr>';

    //display the picture if there is one

    if (@file_exists($product['productid'].'.jpg'))

    {

$myproduct = GetImageSize(($product['productid'].'.jpg'));

 

echo '<img src='.($product['productid']).'.jpg border= '.img_resize($myproduct[0], 

      $myproduct[1], 450).' />';     

 

    }

 

    echo '<td><ul>';

    echo '</li><li><b>Price:</b> £';

    echo number_format($product['price'], 2);

    echo '</li><li><b>Colour:</b> ';

    echo $product['colour'];

    echo '<li><b>Fabric:</b> ';

    echo $product['fabric'];

    echo '</li></ul></td></tr></table>';?>

  <form action="showCart.php" method="post">

    Select size:

    <select name="size">

      <option value=""></option>

      <option value="6">6</option>

      <option value="8">8</option>

      <option value="10">10</option>

      <option value="12">12</option>

        <option value="14">14</option>

    </select> <br/>

Select quantity:

    <select name="quantity">

      <option value="1">1</option>

      <option value="2">2</option>

      <option value="3">3</option>

      <option value="4">4</option>

      <option value="5">5</option>

    </select>

 

<?php

  }

  else

    echo 'The details of this book cannot be displayed at this time.';

  echo '<hr />';

}

 

 

 

 

function do_html_footer()

{

?>

  </form>

  </body>

  </html>

<?php

}

 

function do_html_url($url, $name)

{

?>

  <a href="<?php echo $url; ?>"><?php echo $name; ?></a><br />

<?php

}

 

function do_html_header($title = '')

{

  // print an HTML header

 

  // declare the session variables we want access to inside the function 

  if(!$_SESSION['items']) $_SESSION['items'] = '0';

  if(!$_SESSION['total_price']) $_SESSION['total_price'] = '0.00';

?>

  <html>

  <head>

    <title><?php echo $title; ?></title>

    <style>

      h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color = red; margin = 6px }

      body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

      li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

      hr { color: #FF0000; width=70%; text-align=center}

      a { color: #000000 }

    </style>

  </head>

  <body>

  <table width='100%' border=0 cellspacing = 0 bgcolor='#cccccc'>

  <tr>

  <td rowspan = 2>

  <a href = 'index.php'><img src='Collections.jpg' alt='Collections' border=0

      align='left' valign='bottom' height = 55 width = 325></a>

  </td>

  <td align = 'right' valign = 'bottom'>

  <?php if(isset($_SESSION['admin_user']))

      echo ' ';

    else

      echo 'Total Items = '.$_SESSION['items'];

  ?>

  </td>

  <td align = 'right' rowspan = 2 width = 135>

  <?php //if(isset($_SESSION['admin_user']))

      //display_button('logout.php', 'log-out', 'Log Out');

    //else

      display_button('showCart.php', 'view-cart', 'View Cart');

  ?>

  </tr>

  <tr>

  <td align = right valign = top>

  <?php if(isset($_SESSION['admin_user']))

      echo ' ';

    else

      echo 'Total Price = £'.number_format($_SESSION['total_price'],2);

  ?>

  </td>

  </tr>

  </table>

<?php

  if($title)

    do_html_heading($title);

}

 

function do_html_heading($title)

{

?>

  <h3><?php echo $title; ?></h3>

<?php

}

 

 

function img_resize($width, $height, $target)

{

 

  if ($width > $height)

  {

    $percentage = ($target / $width);

  }

  else

  {

    $percentage = ($target / $height);

  }

 

  $width = round($width * $percentage);

  $height = round($height * $percentage);

 

  return "width=\"$width\" height=\"$height\"";

}

 

function display_button($target, $image, $alt)

{

  echo "<center><a href=\"$target\"><img src=\"$image".".gif\"

          alt=\"$alt\" border=0 height =32 width = 100></a></center>";

}

 

function display_form_button($image, $alt)

{

  echo "<center><input type =  image src=\"$image".".gif\"

          alt=\"$alt\" border=0 height = 32 width = 100></center>";

}

 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429667
Share on other sites

Both of those pages use $productid = $_GET['productid'];

So one page can't send it to another if it doesn't have it.  So we're back to square one, where does $productid get set.

 

those were both the same pages showproduct... u asked to see showproduct

Link to comment
https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429697
Share on other sites

Both of those pages use $productid = $_GET['productid'];

So one page can't send it to another if it doesn't have it.  So we're back to square one, where does $productid get set.

 

those were both the same pages showproduct... u asked to see showproduct

 

theres nothing wrong with the passing of values because i had this working using a button to add the contents to the cart. But i had to change it around because the button was not submitting the form values. I want the user to be able to select a size and then show the size on the cart but this wasnt working previously as it wasnt a submit button so theres nothing wrong with produtid variable its the the line form action ........

Link to comment
https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429703
Share on other sites

Let's break this down a bit for you and maybe you can see where the error is since all of us are confused enough.

 

You need to send a URL to the page that has

 

$productid = $_GET['productid'];

 

This URL should be something like filename.php?productid=5 for example.

 

When the page $_GETs this id, you store it like in the $_GET statement above.

 

The form you just posted is POSTing this to a new page called showCart.php?new=5, if and only if $productid has that info.  So if it hasn't made it this far, then your ACTION and METHOD doesn't even matter yet, because it's empty.

 

So you need to follow the variable.  Find the first page of code that sets this productid, see what method it uses to pass it to another page.  If you don't understand the flow, then there is no way we can.

Link to comment
https://forums.phpfreaks.com/topic/84325-embedding-php/page/2/#findComment-429712
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.