Wizard, Sub, Gum, Inet And All

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Wizard, Sub, Gum, Inet And All

    i got what i want for long time a paypal shop script but help need with little modification here the coding


    cart.php

    Code:
    <?
    include("db.php");
             
    mysql_connect($db_host, $db_user, $db_password);
    
    mysql_select_db($db_name);
    
    $transaction_id = $HTTP_POST_VARS["transaction_id"];
    
    if($transaction_id == "0")
      {
      $insert = "insert into transactions (date) values (CURDATE())";
      mysql_query($insert);
      
      $transaction_id = mysql_insert_id();
      $onload = "onload=\"document.cart.submit();\"";  
      }
    
    $select = "select id from items order by ordre";
    $ids = mysql_query($select);
    while(($id = mysql_fetch_assoc($ids)) && $transaction_id != "")
         {
         $item_id = $HTTP_POST_VARS["item_id_" . $id["id"]];
         
         if($item_id == &#39;on&#39;)
           {
           $order_quantity = $HTTP_POST_VARS["order_quantity_" . $id["id"]];
           if($order_quantity == "")
              $order_quantity = 1;
           
           //Forces a change in the row, otherwise mysql_affected_rows() will
           //return a 0, when no changes are made.
           $update = "update orders set " . 
                     " quantity = 0" . 
                     " where item_id = " . $id["id"] . " and transaction_id = " . $transaction_id;
           mysql_query($update);
           
           $update = "update orders set " . 
                     " quantity = " . $order_quantity . 
                     " where item_id = " . $id["id"] . " and transaction_id = " . $transaction_id;
           mysql_query($update);              
           
           if(mysql_affected_rows() == 0)
             {
             $insert = "insert into orders (item_id, transaction_id, quantity) values (" .
                       $id["id"] . ", " . $transaction_id . ", " . $order_quantity . ")";
             mysql_query($insert);
             }
           }
         else
           {
           $delete = "delete from orders " .  
                     "where item_id = " . $id["id"] . " and transaction_id = " . $transaction_id;
           mysql_query($delete);
           }
         }
    ?>
    <html>
    
    <head>
    <title>item shopping cart</title>
    
    <script>
    function transact()
             {         
             transaction_id = &#39;<?= $transaction_id ?>&#39;;
             
             if(transaction_id == &#39;&#39;) 
                transaction_id = &#39;0&#39;;
                
             document.cart.transaction_id.value = transaction_id;                  
             }                  
    </script>
    </head>
    
    <body <?= $onload ?>>
    <form method="post" name="cart">
    
    <input type="hidden" name="transaction_id" value="<?= $transaction_id ?>" />
    
    <table align="center">
    
    <?
    $select = "select items.id, name, price, summary, thumbnail, quantity " . 
              "from (items left outer join orders on items.id = orders.item_id and transaction_id = ";
              
    if($transaction_id == "")         
       $select .= 0;
    else
       $select .= $transaction_id;
       
    $select .= ") order by ordre";
    
    $items = mysql_query($select);
    
    while($item = mysql_fetch_assoc($items)) { 
    
    $item_id = $item["id"];
    $item_name = $item["name"];
    $item_price = $item["price"];
    $item_summary = $item["summary"];
    $item_thumbnail = $item["thumbnail"];
    $item_ordre = $item["ordre"];
    $order_quantity = $item["quantity"];
    
    if(is_dir("images/") == false)
       mkdir("images/", 0755);
    
    $thumbnail_file = "images/item_" . $item_id . "_thumbnail.jpg";
    if($item_thumbnail != "")
      {  
      $thumbnail_file_handle = fopen("./" . $thumbnail_file, "wb");
      fwrite($thumbnail_file_handle, $item_thumbnail, strlen($item_thumbnail));
      chmod("./" . $thumbnail_file, 0644);
      }
    
    $image_file = "images/item_" . $item_id . "_image.jpg";
    if($item_image != "")
      {  
      $image_file_handle = fopen("./" . $image_file, "wb");
      fwrite($image_file_handle, $item_image, strlen($item_image));
      chmod("./" . $image_file, 0644);
      }
    ?>
    
    
    
    <tr>
    <td valign="top">
        <table>
        <tr>    
        <td>[b]<?= $item_name ?>[/b]</td>
        </tr>
        
        <tr>    
        <td><?= $item_price ?></td>
        </tr>
        
        <tr>    
        <td><?= $item_summary  ?></td>
        </tr>  
        
        <tr>    
        <td>order: <input type="checkbox" name="item_id_<?= $item_id ?>" 
                          <? if($order_quantity != "") { ?>checked<? } ?>
                          onchange="transact();" /></td>
        </tr> 
        
        <tr>    
        <td>quantity: <input type="text" name="order_quantity_<?= $item_id ?>" size="3"
                             value="<?= $order_quantity ?>"
                             onchange="transact();" /></td>
        </tr>         
        </table>
    </td>
    
    <td align="right" valign="top" nowrap>
    <? if($item_thumbnail != "") { ?>
    <img name="thumbnail_file_<?= $item_id ?>" src="<?= $thumbnail_file ?>" />
    <? } ?>
    </td>
    </tr>
    
    <? } ?>
    
    <tr>
    <td><input type="submit" value="purchase"></td>
    
    <? if($transaction_id != "")  { ?>
    
    <?
    $select = "select price, quantity from items, orders " .
              "where items.id = orders.item_id and transaction_id = " . $transaction_id;
    $sub_totals = mysql_query($select);
    
    $total = 0;
    while($sub_total = mysql_fetch_assoc($sub_totals))
         {
         $total += $sub_total["price"] * $sub_total["quantity"];
         }          
    
    $product = "product-id" . $transaction_id;
          
    $business_email = "sales@some-email.com";
                  
    $paypal = "https://www.paypal.com/cgi-bin/webscr/?business=" . $business_email . 
              "&item_name=" . $product .
              "&item_number=" . $product . 
              "&currency_code=USD&amount=" . $total .
              "&cmd=_xclick&no_note=1";
    ?>
    
    <td>
    <? if($total > 0) { ?>
    $<?= $total ?>
    [url="<?= $paypal ?>"]PayPal[/url]
    <? } ?>
    </td>
    
    <? } ?>
    </tr>
    </table>
    </form>
    </body>
    </html>
    edit.php

    Code:
    <?
    include("db.php");
    
    $UserName = "";
    $PassWord = "";
    $isLogged = true;
    
    if(isset($HTTP_COOKIE_VARS["UserName"]) &&
       isset($HTTP_COOKIE_VARS["PassWord"]))
            {
            $UserName = $HTTP_COOKIE_VARS["UserName"];
            $PassWord = $HTTP_COOKIE_VARS["PassWord"];
            }
             
    if(mysql_connect($db_host, $UserName, $PassWord) === false ||
      ($UserName == "" || $PassWord == ""))
      $isLogged = false;
    else
      mysql_select_db($db_name);  
    
    $item_id = $HTTP_POST_VARS["id"];
    //$item_id gets used as a flag for when a new item is created.
    if($item_id != "" && $isLogged == true)
      {
      $name = $HTTP_POST_VARS["name"];
      $price = $HTTP_POST_VARS["price"];
      $summary = $HTTP_POST_VARS["summary"];
      $description = $HTTP_POST_VARS["description"];  
      $ordre = $HTTP_POST_VARS["ordre"];
      if($ordre == "")
         $ordre = "0";
      
      $update = "update items set ordre = ordre + 1 where ordre >= " . $ordre;
      mysql_query($update);
      
      $insert = "insert into items (name, price, summary, description, ordre) values (" .
                "&#39;" . $name . "&#39;, " .
                $price . ", " .
                "&#39;" . $summary . "&#39;, " .
                "&#39;" . $description . "&#39;, " .
                $ordre . ")";
                  
      mysql_query($insert);  
                
      $item_id = mysql_insert_id();
      
      if(isset($HTTP_POST_FILES))                
        {
        if(is_uploaded_file($HTTP_POST_FILES["thumbnail"]["tmp_name"]))
          {
          $file_handle = fopen($HTTP_POST_FILES["thumbnail"]["tmp_name"], "rb");
          $thumbnail = $HTTP_POST_FILES["thumbnail"]["name"];
          $file_bytes = addslashes(fread($file_handle, 
                                         filesize($HTTP_POST_FILES["thumbnail"]["tmp_name"])));
                                              
          $update = "update items set " .
                    "thumbnail = &#39;" . $file_bytes . "&#39; " .                     
                    "where id = " . $item_id;
          mysql_query($update);
                         
          unlink($HTTP_POST_FILES["thumbnail"]["tmp_name"]);
          }
               
        if(is_uploaded_file($HTTP_POST_FILES["image"]["tmp_name"]))
          {
          $file_handle = fopen($HTTP_POST_FILES["image"]["tmp_name"], "rb");
          $image = $HTTP_POST_FILES["image"]["name"];
          $file_bytes = addslashes(fread($file_handle, 
                                         filesize($HTTP_POST_FILES["image"]["tmp_name"])));
                                              
          $update = "update items set " .
                    "image = &#39;" . $file_bytes . "&#39; " .                     
                    "where id = " . $item_id;
          mysql_query($update);
                                              
          unlink($HTTP_POST_FILES["image"]["tmp_name"]);
          }
        }
      }
    
    $select = "select id from items order by ordre";
    $ids = mysql_query($select);
    while(($id = mysql_fetch_assoc($ids)) && $isLogged == true)
         {     
         $item_id = $HTTP_POST_VARS["id_" . $id["id"]];
         //If the item was modified, save it.
         if($item_id != "" && $item_id > 0)
           {
           $name = $HTTP_POST_VARS["name_" . $id["id"]];
           $price = $HTTP_POST_VARS["price_" . $id["id"]];
           $summary = $HTTP_POST_VARS["summary_" . $id["id"]];
           $description = $HTTP_POST_VARS["description_" . $id["id"]];       
           $ordre = $HTTP_POST_VARS["ordre_" . $id["id"]];
           
           $update = "update items set " .
                     "name = &#39;" . $name . "&#39;, " .
                     "price = " . $price . ", " .
                     "summary = &#39;" . $summary . "&#39;, " .
                     "description = &#39;" . $description . "&#39;, " .
                     "ordre = " . $ordre . " " .
                     "where id = " . $item_id;
                     
           mysql_query($update);
             
           //Were any files uploaded?        
           if(isset($HTTP_POST_FILES))                
             {         
             if(is_uploaded_file($HTTP_POST_FILES["thumbnail_" . $item_id]["tmp_name"]))
               {           
               $file_handle = fopen($HTTP_POST_FILES["thumbnail_" . $item_id]["tmp_name"], "rb");
               $thumbnail = $HTTP_POST_FILES["thumbnail_" . $item_id]["name"];
               $file_bytes = addslashes(fread($file_handle, 
                                              filesize($HTTP_POST_FILES["thumbnail_" . $item_id]["tmp_name"])));
                                              
               $update = "update items set " .
                         "thumbnail = &#39;" . $file_bytes . "&#39; " .                     
                         "where id = " . $item_id;
               mysql_query($update);
                         
               unlink($HTTP_POST_FILES["thumbnail_" . $item_id]["tmp_name"]);
               }
               
             if(is_uploaded_file($HTTP_POST_FILES["image_" . $item_id]["tmp_name"]))
               {
               $file_handle = fopen($HTTP_POST_FILES["image_" . $item_id]["tmp_name"], "rb");
               $image = $HTTP_POST_FILES["image_" . $item_id]["name"];
               $file_bytes = addslashes(fread($file_handle, 
                                              filesize($HTTP_POST_FILES["image_" . $item_id]["tmp_name"])));
                                              
               $update = "update items set " .
                         "image = &#39;" . $file_bytes . "&#39; " .                     
                         "where id = " . $item_id;
               mysql_query($update);
                                              
               unlink($HTTP_POST_FILES["image_" . $item_id]["tmp_name"]);
               }
             }
           }
           
         //Delete items.
         if($item_id != "" && $item_id < 0)
           {
           $delete = "delete from items where id = " . (-$item_id);
           
           mysql_query($delete);
           
           unlink("./images/item_" . (-$item_id) . "_thumbnail.jpg");
           unlink("./images/item_" . (-$item_id) . "_image.jpg");
           }
         }
    
    $select = "select * from items order by ordre";
    $items = mysql_query($select);
    ?>
    <html>
    
    <head>
    <title>item shopping cart edit</title>
    
    <script>
    function NewImage(id)
             {
             var File;
             var Image;
             var Save;
             
             if(id != null)
               {
               eval(&#39;File = document.cart.image_&#39; + id + &#39;;&#39;);
               eval(&#39;Image = document.images.image_file_&#39; + id + &#39;;&#39;);
               }
             else
               {
               File = document.cart.image;
               Image = document.images.image_file;
               }
             
             if(File.value != &#39;&#39;)
               {
               Image.src = File.value;
               save_item(id);
               }
             }
             
    function NewThumb(id)
             {
             var File;
             var Image;
             var Save;
             
             if(id != null)
               {
               eval(&#39;File = document.cart.thumbnail_&#39; + id + &#39;;&#39;);
               eval(&#39;Image = document.images.thumbnail_file_&#39; + id + &#39;;&#39;);
               }
             else
               {
               File = document.cart.thumbnail;
               Image = document.images.thumbnail_file;
               }
             
             if(File.value != &#39;&#39;)
               {
               Image.src = File.value;
               save_item(id);
               }
             }
             
    function save_item(id)
             {
             if(id != null)
                eval(&#39;document.cart.id_&#39; + id + &#39;.value = &#39; + id + &#39;;&#39;);
             else
                document.cart.id.value = 0;
             }
             
    function delete_item(id)
             {         
             eval(&#39;document.cart.id_&#39; + id + &#39;.value = &#39; + (-id) + &#39;;&#39;);   
             document.cart.submit();      
             }
             
    function logout()
             {
             document.cookie = &#39;UserName=&#39;;
             document.cookie = &#39;PassWord=&#39;;
             
             document.cart.submit();
             }
    </script>
    </head>
    
    <body <? if($HTTP_POST_VARS["id"] != "") { ?>onload="document.cart.ordre.value = &#39;&#39;; document.cart.submit();"<? } ?>>
    <form enctype="multipart/form-data" method="post" name="cart">
    <input type="hidden" name="ordre" value="<?= $HTTP_POST_VARS["ordre"] ?>" />
    
    <table align="center">
    
    <? if((mysql_num_rows($items) == 0 || $HTTP_POST_VARS["ordre"] != "") 
          && $HTTP_POST_VARS["id"] == "" && $isLogged == true) { ?>
    
    <input type="hidden" name="id" />
    
    <tr>
    <td valign="top">
        <table>
        <tr>
        <td>item name: </td>
        <td><input type="text" name="name" onchange="save_item();" /></td>
        </tr>
        
        <tr>
        <td>price: </td>
        <td><input type="text" name="price" onchange="save_item();" /></td>
        </tr>
        
        <tr>
        <td>summary: </td>
        <td><textarea name="summary" onchange="save_item();"></textarea></td>
        </tr>
        
        <tr>
        <td>description: </td>
        <td><textarea name="description" onchange="save_item();"></textarea></td>        
        </td>
        </tr>
                
        <tr>
        <td>
        <input type="button" value="save" 
               onclick="document.cart.submit();"/>
                        
        
        <input type="button" value="cancel" 
               onclick="document.cart.ordre.value = &#39;&#39;;
                        document.cart.id.value = &#39;&#39;;
                        document.cart.submit();"/>
                        
                           
        <input type="button" value="log out" 
               onclick="logout();" />
        
        
    
    </td>        
        </tr>
        </table>
    </td>
    
    <td align="right" valign="top" nowrap>
    thumbnail: <input type="file" name="thumbnail" onchange="NewThumb();" />
    
    
    <img name="thumbnail_file" />
    
    
    image: <input type="file" name="image" onchange="NewImage();" />
    
    
    <img name="image_file" />
    </td>
    </tr>
    
    <? } ?>
    
    <? 
    while(($item = mysql_fetch_assoc($items)) && ($HTTP_POST_VARS["id"] == null) && ($isLogged == true)) { 
    
    $item_id = $item["id"];
    $name = $item["name"];
    $price = $item["price"];
    $summary = $item["summary"];
    $description = $item["description"];
    $thumbnail = $item["thumbnail"];
    $image = $item["image"];
    $ordre = $item["ordre"];
    
    if(is_dir("images/") == false)
       mkdir("images/", 0755);
    
    $thumbnail_file = "images/item_" . $item_id . "_thumbnail.jpg";
    if($thumbnail != "")
      {
      $thumbnail_file_handle = fopen("./" . $thumbnail_file, "wb");
      fwrite($thumbnail_file_handle, $thumbnail, strlen($thumbnail));
      chmod("./" . $thumbnail_file, 0644);
      }
    
    $image_file = "images/item_" . $item_id . "_image.jpg";
    if($image != "")
      {  
      $image_file_handle = fopen("./" . $image_file, "wb");
      fwrite($image_file_handle, $image, strlen($image));
      chmod("./" . $image_file, 0644);
      }
    ?>
    
    <input type="hidden" name="id_<?= $item_id ?>" />
    
    <tr>
    <td valign="top">
        <table>
        <tr>
        <td>item name: </td>
        <td><input type="text" name="name_<?= $item_id ?>" value="<?= $name ?>" 
                   onchange="save_item(<?= $item_id ?>);" /></td>
        </tr>
        
        <tr>
        <td>price: </td>
        <td><input type="text" name="price_<?= $item_id ?>" value="<?= $price ?>" 
                   onchange="save_item(<?= $item_id ?>);" /></td>
        </tr>
        
        <tr>
        <td>summary: </td>
        <td><textarea name="summary_<?= $item_id ?>" 
                      onchange="save_item(<?= $item_id ?>);"><?= $summary  ?></textarea></td>
        </tr>
        
        <tr>
        <td>description: </td>
        <td><textarea name="description_<?= $item_id ?>" 
                      onchange="save_item(<?= $item_id ?>);"><?= $description  ?></textarea></td>
        </tr>
        
        <tr>
        <td>order: </td>
        <td><input type="text" name="ordre_<?= $item_id ?>" value="<?= $ordre ?>"
                   onchange="save_item(<?= $item_id ?>);" /></td>
        </tr>
        
        <tr>
        <td>
        <input type="button" value="add a new item" 
               onclick="document.cart.ordre.value = <?= $ordre + 1 ?>;
                        document.cart.submit();"/>
         
                           
        <input type="submit" value="save" />
        
                           
        <input type="button" value="delete" 
               onclick="delete_item(<?= $item_id ?>);" />
               
                           
        <input type="button" value="log out" 
               onclick="logout();" />
        
        
    
    
        </td>
        </tr>
        </table>
    </td>
    
    <td align="right" valign="top" nowrap>
    thumbnail: <input type="file" name="thumbnail_<?= $item_id ?>" onchange="NewThumb(<?= $item_id ?>);" />
    
    
    <img name="thumbnail_file_<?= $item_id ?>" src="<?= $thumbnail_file ?>" />
    
    
    image: <input type="file" name="image_<?= $item_id ?>" onchange="NewImage(<?= $item_id ?>);" />
    
    
    <img name="image_file_<?= $item_id ?>" src="<?= $image_file ?>" />
    
    
    </td>
    </tr>
    
    <? } ?>
    
    <? if($isLogged == false) { ?>
    <tr>
    <td>User Name </td>
    <td><input type="text" name="User" /></td>
    </tr>
    
    <tr>
    <td>Password</td>
    <td><input type="password" name="Pass" /></td>
    </tr>
    
    <tr>
    <td colspan="2" align="right">
    <input type="button" value="log in"
           onclick="document.cookie = &#39;UserName=&#39; + document.cart.User.value;
                    document.cookie = &#39;PassWord=&#39; + document.cart.Pass.value;
                    document.cart.submit();">
    </td>
    </tr>
    <? } ?>
    
    </table>
    </form>
    </body>
    </html>
    and sql

    create table items
    (
    id int primary key AUTO_INCREMENT,
    name varchar(255),
    price decimal(6,2),
    summary tinytext,
    description text,
    thumbnail blob,
    image blob,
    ordre int
    );

    create table orders
    (
    id int primary key AUTO_INCREMENT,
    item_id int,
    transaction_id int,
    quantity int
    );

    create table transactions
    (
    id int primary key AUTO_INCREMENT,
    date date
    );
    Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

    <span style="color:#9ACD32"><span style="font-size:36pt;line-height:100%">BEST MOBILE ADVERTISER</span></span>


    #2
    cart.php fine but edit have some bug it asks for ftp logins on top of script and after u put ftp details i get this

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user &#39;www&#39;@&#39;localhost&#39; (using password: NO) in /home/www/public_html/cart1/edit.php on line 15

    Warning: mysql_query() [function.mysql-query]: Access denied for user &#39;www&#39;@&#39;localhost&#39; (using password: NO) in /home/www/public_html/cart1/edit.php on line 82

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/www/public_html/cart1/edit.php on line 82

    Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/www/public_html/cart1/edit.php on line 83

    Warning: mysql_query() [function.mysql-query]: Access denied for user &#39;www&#39;@&#39;localhost&#39; (using password: NO) in /home/www/public_html/cart1/edit.php on line 153

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/www/public_html/cart1/edit.php on line 153

    i want to add a user inseatd of putting ftp in script how to do please help me and also tell me if this script got loop holes. please friends help
    Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

    <span style="color:#9ACD32"><span style="font-size:36pt;line-height:100%">BEST MOBILE ADVERTISER</span></span>

    Comment


      #3
      please someone help fix error i not understand how.
      Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

      <span style="color:#9ACD32"><span style="font-size:36pt;line-height:100%">BEST MOBILE ADVERTISER</span></span>

      Comment


        #4
        check your config.php cause it seems like you put a wrong thing (might be a wrong password or username) you might be running or testing your script in your local server and forgot to change it when you uploaded it in your host.

        Comment


          #5
          no bru i did right way but the edit php giving those error db all correct pws and all fine please check the script u get it too please help me
          Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

          <span style="color:#9ACD32"><span style="font-size:36pt;line-height:100%">BEST MOBILE ADVERTISER</span></span>

          Comment


            #6
            Code:
            if(isset($HTTP_COOKIE_VARS["UserName"]) &&
               isset($HTTP_COOKIE_VARS["PassWord"]))
                    {
                    $UserName = $HTTP_COOKIE_VARS["UserName"];
                    $PassWord = $HTTP_COOKIE_VARS["PassWord"];
                    }
                    
            if(mysql_connect($db_host, $UserName, $PassWord) === false ||
              ($UserName == "" || $PassWord == ""))
            im not familiar with this script so ive breifly scanned it .. why would you use the users cookie values to connect to the database ???

            shouldnt the connect simply be
            Code:
            mysql_connect($db_host, $db_user, $db_password);
            
            mysql_select_db($db_name);

            Comment


              #7
              yes bru even i know it asking my ftp password to login please help me edit this coding and make a user to login instead of putting ftp login :sad:
              Failure is not when a girls leaves you, its only when you let her go virgin. heheh!!

              <span style="color:#9ACD32"><span style="font-size:36pt;line-height:100%">BEST MOBILE ADVERTISER</span></span>

              Comment

              Working...
              X