Jump to content

This is prob really simple for you guys but help needed really fast


rn14

Recommended Posts

My problem is whenever I run the code below I get the following error

 

Warning: Invalid argument supplied for foreach() in /home/seachange/domains/sea-change.ie/public_html/cart1/show_cart.php on line 122

 

However when I just run the php part of this code on its own it runs perfectly and executes everything.

 

As you prob can see Im a beginner but if their is a fix to this please let me know

 

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<!-- TemplateBeginEditable name="doctitle" -->

<title>Untitled Document</title>

<!-- TemplateEndEditable -->

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!-- TemplateBeginEditable name="head" -->

<!-- TemplateEndEditable -->

<style type="text/css">

.newStyle1 {

border-right-style: dotted;

border-right-width: thin;

border-right-color: #0000FF;

}

.newStyle2 {

border: thin solid #0000FF;

}

.style4 {

border: 0px solid #0000FF;

}

.style6 {

border: 1px solid #0000FF;

}

.newStyle3 {

border-width: thin;

border-color: #0000FF;

}

.style10 {

color: #0000FF;

}

.style16 {

text-decoration: none;

}

.newStyle4 {

background-color: #3366FF;

}

.newStyle5 {

background-color: #FFFFFF;

}

</style>

</head>

 

<body class="newStyle4">

<div align="center">

  <table width="51%" border="1" class="newStyle5">

    <tr>

      <td><table width="51%" height="689" border="0" align="center" class="newStyle5">

      <tr>

        <td height="685" valign="top">

          <table width="100%" border="0">

            <tr>

              <td width="61%"><img src="seachangenewlogo1.jpg" width="300" height="166"></td>

          <td width="39%"><p><img src="Untitled-2.png" width="280" height="90"></p>

            </td>

        </tr>

      </table>

          <hr class="style10">

          <table width="100%" border="0">

            <tr>

              <td width="17%" valign="top">

<table width="136" border="0" class="style4" style="width: 95px">

                  <tr class="newStyle2">

                    <td width="128" class="style6" style="width: 87px" valign="top">

                      <a href="index.html" class="style16"> Home</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      About Us</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      Our Events</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      Newsletter</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      Donate Online</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      Our Work</a></td>

                  </tr>

                  <tr>

                    <td class="style6" style="width: 87px"> <a href="index.html" class="style16">

                      Contact Us</a></td>

                  </tr>

                </table></td>

              <td width="83%" valign="top">

<div align="left">

                  <p align="left  </p><?session_start();

?>

"><?

  include ('book_sc_fns.php');

  // The shopping cart needs sessions, so start one

 

  if($new)

  {

    //new item selected

    if(!session_is_registered("cart"))

    {

      $cart = array();

      session_register("cart");

      $items = 0;

      session_register("items");

      $total_price = "0.00";     

      session_register("total_price");

    }

    if($cart[$new])

      $cart[$new]++;

    else

      $cart[$new] = 1;

    $total_price = calculate_price($cart);

    $items = calculate_items($cart);

 

  }

  if($save)

  {

  foreach ($cart as $isbn => $qty)

    {

    if($$isbn=="0")

    unset($cart[$isbn]);

    else

    $cart[$isbn] = $$isbn;

    }

    $total_price = calculate_price($cart);

    $items = calculate_items($cart);

}

 

  do_html_header("Your shopping cart");

 

  if($cart&&array_count_values($cart))

    display_cart($cart);

  else

  {

    echo "<p>There are no items in your cart";

    echo "<hr>";

  }

  $target = "index.php";

 

  // if we have just added an item to the cart, continue shopping in that category

  if($new)

  {

    $details =  get_book_details($new);

    if($details["catid"])   

      $target = "show_cat.php?catid=".$details["catid"];

  }

  display_button($target, "continue-shopping", "Continue Shopping"); 

  $path = $PHP_SELF;

  $path = str_replace("show_cart.php", "", $path);

  display_button("https://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout"); 

  do_html_footer();

?> </p>

                  <p><br>

                  </p>

                  </div>

                </td>

            </tr>

          </table>

          <hr>

          <p><font color="#0000FF" size="2">©2007 Seachange</font></p></td>

    </tr>

  </table>

Link to comment
Share on other sites

You posted way too much code, and didn't use the code tags, so it's annoying to try to edit it.

As I said twice, before the foreach on the line which is causing problems, add another if statment to check the values of the array. It seems the array is empty.

Link to comment
Share on other sites

Added the php code on its own. no its not receiving values. When I use this php code on its own it works perfectly

 

<?session_start();

?>

"><?

  include ('book_sc_fns.php');

  // The shopping cart needs sessions, so start one

 

  if($new)

  {

    //new item selected

    if(!session_is_registered("cart"))

    {

      $cart = array();

      session_register("cart");

      $items = 0;

      session_register("items");

      $total_price = "0.00";     

      session_register("total_price");

    }

    if($cart[$new])

      $cart[$new]++;

    else

      $cart[$new] = 1;

    $total_price = calculate_price($cart);

    $items = calculate_items($cart);

 

  }

  if($save)

  {

  foreach ($cart as $isbn => $qty)

    {

    if($$isbn=="0")

    unset($cart[$isbn]);

    else

    $cart[$isbn] = $$isbn;

    }

    $total_price = calculate_price($cart);

    $items = calculate_items($cart);

}

 

  do_html_header("Your shopping cart");

 

  if($cart&&array_count_values($cart))

    display_cart($cart);

  else

  {

    echo "<p>There are no items in your cart";

    echo "

--------------------------------------------------------------------------------

";

  }

  $target = "index.php";

 

  // if we have just added an item to the cart, continue shopping in that category

  if($new)

  {

    $details =  get_book_details($new);

    if($details["catid"])   

      $target = "show_cat.php?catid=".$details["catid"];

  }

  display_button($target, "continue-shopping", "Continue Shopping"); 

  $path = $PHP_SELF;

  $path = str_replace("show_cart.php", "", $path);

  display_button("https://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout"); 

  do_html_footer();

?>

 

 

 

Link to comment
Share on other sites

This is the code that runs the script correctly.

 

Whenever i add any html to the script it produces that error

 

 

<?session_start();
?>
"><?
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  
  if($new)
  {
    //new item selected
    if(!session_is_registered("cart"))
    {
      $cart = array();
      session_register("cart");
      $items = 0;
      session_register("items");
      $total_price = "0.00";      
      session_register("total_price");
    }
    if($cart[$new])
      $cart[$new]++;
    else 
      $cart[$new] = 1;
    $total_price = calculate_price($cart);
    $items = calculate_items($cart);

  }
  if($save)
  {
   foreach ($cart as $isbn => $qty)
    {
    if($$isbn=="0")
     unset($cart[$isbn]);
    else 
     $cart[$isbn] = $$isbn;
    }
    $total_price = calculate_price($cart);
    $items = calculate_items($cart);
}

  do_html_header("Your shopping cart");

  if($cart&&array_count_values($cart))
    display_cart($cart);
  else
  {
    echo "<p>There are no items in your cart";
    echo "
--------------------------------------------------------------------------------
";
  }
  $target = "index.php";

  // if we have just added an item to the cart, continue shopping in that category
  if($new)
  {
    $details =  get_book_details($new);
    if($details["catid"])    
      $target = "show_cat.php?catid=".$details["catid"]; 
  }
  display_button($target, "continue-shopping", "Continue Shopping");  
  $path = $PHP_SELF;
  $path = str_replace("show_cart.php", "", $path);
  display_button("https://".$SERVER_NAME.$path."checkout.php", "go-to-checkout", "Go To Checkout");  
  do_html_footer();
?>

 

 

 

 

 

 

 

Link to comment
Share on other sites

If you're only going to read half of my post each time this is going to take forever.

 

Your original post doesn't have session_start(); When you add your HTML, add it AFTER your session_start(); Try it then.

Where does $cart get defined?

Link to comment
Share on other sites

That fixed it. Sometimes I wonder about myself!!! Just looked at your site you seem to be a bit of a legend with a very good attitude. Im from Ireland fairly big into rugby so look after myself too. If u have any tips on learning php or just in general please let me know!! Thanks again for your help!

Link to comment
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.