Jump to content

rn14

Members
  • Posts

    111
  • Joined

  • Last visited

    Never

Posts posted by rn14

  1. Im attempting to pass the total value of a shopping cart to paypal. Im certain the value is in the variable $amount (printed it on the previous line) however this isnt passed to the paypal page.

    badly need a solution to this!!

     

     

    function display_checkout_form()
    {
       ?>
    
    
    <?
    global $total_price;
      global $items;
      if(!$items) $items = "0";
      if(!$total_price) $total_price = "0.00";
      ?>
    <? if(session_is_registered("admin_user"))
         echo " ";
         else
         echo "<br>Total Items = $items<br>"; 
      ?>
      </td>
      <td align = center rowspan = 2 width = 135>
      <? if(session_is_registered("admin_user"))
         display_button("logout.php", "log-out", "Log Out");
        else
       // display_button("show_cart.php", "view-cart", "View Your Shopping Cart");
      ?>
      </tr>
      <tr>
      <td align = center valign = top>
      <? if(session_is_registered("admin_user"))
           echo " ";
         else
         echo "Total Price = €".number_format($total_price); 
    
      ?>
    
    <form action="https://www.paypal.com/ie/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="">
    <input type="hidden" name="item_name" value="">
    <input type="hidden" name="currency_code" value="EUR">
    <?$amount = $total_price;
    echo $amount;
    ?>
    <input type="hidden" name="amount" value="<?$amount?>">
    <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
    
    

  2. I have a simple problem I have a variable with the name $total_price which holds the values of items sold in a shopping cart. Is it possible to pass the value of this variable to a variable called $amount??????

     

    Thanks!

  3. Below is the code that displays html and defines many functions. All I need to do is to pass the value of $total_price to the value of amount in the paypal form. This is inside the displaycheckoutform function(I have highlighted in red where the value needs to be passed too). I have also included the form that calls the function to display the checkout page after this initial code. I have tried a few things but am not that experienced and would massively appreciate some help.

     

     

    output.php

    <?
    
    function do_html_header($title = '')
    {
      // print an HTML header
    
      // declare the session variables we want access to inside the function 
      global $total_price;
      global $items;
      if(!$items) $items = "0";
      if(!$total_price) $total_price = "0.00";
    ?>
      <html>
      <head>
        <title><?=$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: 14px }
          hr { width=100%; text-align=center}
          a { color: #0000FF }
    
        </style>
      </head>
      <body>
      <table width=100% border=0 cellspacing = 0 bgcolor=#ffffff>
      <tr>
      <td rowspan = 2>
      <a href = "index.php"><img src="images/Book-O-Rama.gif" alt="SeaChange Events" border=0
           align=left valign=top height = 55 width = 300></a>
      </td>
      <td align = right valign = top>
      <? if(session_is_registered("admin_user"))
         echo " ";
         //else
          //echo "<br>Total Items = $items<br>"; 
      ?>
      </td>
      <td align = center rowspan = 2 width = 135>
      <? if(session_is_registered("admin_user"))
         display_button("logout.php", "log-out", "Log Out");
        else
       // display_button("show_cart.php", "view-cart", "View Your Shopping Cart");
      ?>
      </tr>
      <tr>
      <td align = center valign = top>
      <? if(session_is_registered("admin_user"))
           echo " ";
         //else
         //echo "Total Price = €".number_format($total_price,2); 
      ?>
      </td>
      </tr>
      </table>
    <?
      if($title)
        do_html_heading($title);
    }
    
    function do_html_footer()
    {
      // print an HTML footer
    ?>
      </body>
      </html>
    <?
    }
    
    function do_html_heading($heading)
    {
      // print heading
    ?>
      <h2><?=$heading?></h2>
    <?
    }
    
    function do_html_URL($url, $name)
    {
      // output URL as link and br
    ?>
      <a href="<?=$url?>"><?=$name?></a><br>
    <?
    }
    
    function display_categories($cat_array)
    {
      if (!is_array($cat_array))
      {
         echo "No information on this event currently available<br>";
         return;
      }
      echo "<ul>";
      foreach ($cat_array as $row)
      {
        $url = "show_cat.php?catid=".($row["catid"]);
        $title = $row["catname"]; 
        echo "<li>";
        do_html_url($url, $title); 
      }    
      echo "</ul>";
      echo "";
    }
    
    function display_books($book_array)
    {
      //display all books in the array passed in
      if (!is_array($book_array))
      {
         echo "<br>No information on this event currently availible<br>";
      }
      else
      {
        //create table
        echo "<table width = \"100%\" border = 0>";
        
        //create a table row for each book    
        foreach ($book_array as $row)
        {
          $url = "show_book.php?isbn=".($row["isbn"]);
          echo "<tr><td>";
          if (@file_exists("images/".$row["isbn"].".jpg"))
          {
            $title = "<img src=\"images/".($row["isbn"]).".jpg\" border=0>";
            do_html_url($url, $title);
          }
          else
          {
            echo " ";
          }
          echo "</td><td>";
          $title =  $row["description"]."  ".$row[""];
          do_html_url($url, $title);
          echo "</td></tr>";
        }
        echo "</table>";
      }
      echo "";
    }
    
    function display_book_details($book)
    {
      // display all details about this book
      if (is_array($book))
      {
        echo "<table><tr>"; 
        //display the picture if there is one 
        if (@file_exists("images/".($book["isbn"]).".jpg"))
        {
          $size = GetImageSize("images/".$book["isbn"].".jpg");
          if($size[0]>0 && $size[1]>0)
            echo "<td><img src=\"images/".$book["isbn"].".jpg\" border=0 ".$size[3]."></td>";
        }
        echo "<td><ul>";
        echo "<li><b>Event Location:</b> ";
        echo $book["author"];
       // echo "<li><b></b> ";
        //echo $book["isbn"];
        echo "<li><b>Ticket Price:</b> ";
        echo number_format($book["price"], 2);
        echo "<li><b>Event Description:</b> ";
        echo $book["description"];
        echo "</ul></td></tr></table>"; 
      }
      else
        echo "The details of this book cannot be displayed at this time.";
    
    
      echo "";
    }
    
    function display_checkout_form()
    {
      //display the form that asks for name and address
    ?>
      <br>
      <table border = 0 width = 100% cellspacing = 0>
      <form action = purchase.php method = post>
      <tr><th colspan = 2 bgcolor="#cccccc">Your Details</th></tr>
      <tr>
        <td>Name</td>
        <td><input type = text name = name value = "" maxlength = 40 size = 40></td>
      </tr>
      <tr>
        <td>Address</td>
        <td><input type = text name = address value = "" maxlength = 40 size = 40></td>
      </tr>
      <tr>
        <td>City/Suburb</td>
        <td><input type = text name = city value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr>
        <td>State/Province</td>
        <td><input type = text name = state value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr>
        <td>Postal Code or Zip Code</td>
        <td><input type = text name = zip value = "" maxlength = 10 size = 40></td>
      </tr>
      <tr>
        <td>Country</td>
        <td><input type = text name = country value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr><th colspan = 2 bgcolor="#cccccc">Shipping Address (leave blank if as above)</th></tr>
      <tr>
        <td>Name</td>
        <td><input type = text name = ship_name value = "" maxlength = 40 size = 40></td>
      </tr>
      <tr>
        <td>Address</td>
        <td><input type = text name = ship_address value = "" maxlength = 40 size = 40></td>
      </tr>
      <tr>
        <td>City/Suburb</td>
        <td><input type = text name = ship_city value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr>
        <td>State/Province</td>
        <td><input type = text name = ship_state value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr>
        <td>Postal Code or Zip Code</td>
        <td><input type = text name = ship_zip value = "" maxlength = 10 size = 40></td>
      </tr>
      <tr>
        <td>Country</td>
        <td><input type = text name = ship_country value = "" maxlength = 20 size = 40></td>
      </tr>
      <tr>
        <td colspan = 2 align = center>
          <b>Please press Purchase to confirm your purchase,
             or Continue Shopping to add or remove items</b> 
         <? display_form_button("purchase", "Purchase These Items"); ?>
        </td>
      </tr>
      </form>
    //display the form that asks for name and address
    <form action="https://www.paypal.com/ie/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_xclick">
    <input type="hidden" name="business" value="">
    <input type="hidden" name="item_name" value="">
    <input type="hidden" name="currency_code" value="EUR">
    [font=Verdana]<input type="hidden" name="amount" value="">[/font]
    <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
    </form>
    
    
    
      </table><hr>
    <?
    }
    
    
    
    function display_cart($cart, $change = true, $images = 1)
    {
      // display items in shopping cart
      // optionally allow changes (true or false)
      // optionally include images (1 - yes, 0 - no)
    
      global $items;
      global $total_price;
    
      echo "<table border = 0 width = 100% cellspacing = 0>
            <form action = show_cart.php method = post>
            <tr><th colspan = ". (1+$images) ." bgcolor=\"#cccccc\">Item</th>
            <th bgcolor=\"#cccccc\">Price</th><th bgcolor=\"#cccccc\">Quantity</th>
            <th bgcolor=\"#cccccc\">Total</th></tr>";
    
      //display each item as a table row
      foreach ($cart as $isbn => $qty)
      {
        $book = get_book_details($isbn);
        echo "<tr>";
        if($images ==true)
        {
          echo "<td align = left>";
          if (file_exists("images/$isbn.jpg"))
          {
             $size = GetImageSize("images/".$isbn.".jpg");  
             if($size[0]>0 && $size[1]>0)
             {
               echo "<img src=\"images/".$isbn.".jpg\" border=0 ";
               echo "width = ". $size[0]/3 ." height = " .$size[1]/3 . ">";
             }
          }
          else
             echo " ";
          echo "</td>";
        }
        echo "<td align = left>";
        echo "<a href = \"show_book.php?isbn=".$isbn."\">".$book["title"]."</a> ".$book[""];
        echo "</td><td align = center>€".number_format($book["price"], 2);
        echo "</td><td align = center>";
        // if we allow changes, quantities are in text boxes
        if ($change == true)
          echo "<input type = text name = \"$isbn\" value = $qty size = 3>";
        else
          echo $qty;
        echo "</td><td align = center>€".number_format($book["price"]*$qty,2)."</td></tr>\n";
      }
      // display total row
      echo "<tr>
              <th colspan = ". (2+$images) ." bgcolor=\"#cccccc\"> </td>
              <th align = center bgcolor=\"#cccccc\"> 
                  $items
              </th>
              <th align = center bgcolor=\"#cccccc\">
                  €".number_format($total_price, 2).
              "</th>
            </tr>";
      // display save change button
      if($change == true)
      {
        echo "<tr>
                <td colspan = ". (2+$images) ."> </td>
                <td align = center>
                  <input type = hidden name = save value = true>  
                  <input type = image src = \"images/save-changes.gif\" 
                         border = 0 alt = \"Save Changes\">
                </td>
                <td> </td>
            </tr>";
      }
      echo "</form></table>";
    }
    
    function display_login_form()
    {
      // dispaly form asking for name and password
    ?>
      <form method=post action="admin.php">
      <table bgcolor=#cccccc>
       <tr>
         <td>Username:</td>
         <td><input type=text name=username></td></tr>
       <tr>
         <td>Password:</td>
         <td><input type=password name=passwd></td></tr>
       <tr>
         <td colspan=2 align=center>
         <input type=submit value="Log in"></td></tr>
       <tr>
    </table></form>
    <?
    }
    
    function display_admin_menu()
    {
    ?>
    <br>
    <a href="index.php">Go to main site</a><br>
    <a href="insert_category_form.php">Add a new category</a><br>
    <a href="insert_book_form.php">Add a new book</a><br>
    <a href="change_password_form.php">Change admin password</a><br>
    <?
    
    }
    
    function display_button($target, $image, $alt)
    {
      echo "<center><a href=\"$target\"><img src=\"images/$image".".gif\" 
               alt=\"$alt\" border=0 height = 50 width = 135></a></center>";
    }
    
    function display_form_button($image, $alt)
    {
      echo "<center><input type = image src=\"images/$image".".gif\" 
               alt=\"$alt\" border=0 height = 50 width = 135></center>";
    }
    
    ?>
    
    

     

     

    checkout.php

    <?
      //include our function set
      include ('book_sc_fns.php');
    
      // The shopping cart needs sessions, so start one
      session_start();
    
      do_html_header("Checkout");
      
      if($cart&&array_count_values($cart))
      {
        display_cart($cart, false, 0);
        display_checkout_form();
      }
      else
        echo "<p>There are no items in your cart";
    
      
      do_html_footer();
    ?>
    

  4. 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();
    ?>

     

     

     

     

     

     

     

  5. 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();

    ?>

     

     

     

  6. 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>

×
×
  • 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.