Jump to content

Shopping Cart Code


wOne30

Recommended Posts

Hello Community,

 

I am currently trying to create my own shopping cart system. Here is the code I have so far:

 

<?php

/**
  * connects to database server and selects database
  * @return bool
  */
  function db_connect()
  {
  	  
    $connection = mysql_pconnect('localhost','myusername','mypass');
  	  
    if(!$connection)
    {
      return false;
    }
  	  
    if(!mysql_select_db('amgarden_catalog'))
    {
      return false;
    }

    return $connection;

  }

  
  
/**
  * Turns MYSQL resource into array
  * @param resource $result
  * @return array
  */
  function db_result_to_array($result)
  {
   $res_array = array();
   
   for ($count=0; $row = mysql_fetch_array($result); $count++)
   {
     $res_array[$count] = $row;	   
   }
   
   return $res_array;
   
  }
  
      
  /**
   * finds products and lists them in DESC order
   * @return array
   */
  function find_products()
  {
      db_connect();

  $query = "SELECT * FROM products order by products.id DESC";

  $result = mysql_query($query);
  
  $result = db_result_to_array($result);
  
  return $result;
  
  }
  
   /**
   * finds one product by id
   * @return array
   */
  function find_products($id)
  {
    db_connect();

  $query = sprintf("SELECT * FROM products WHERE products.id = '%s'", 
  	           mysql_real_escape_string($id));

  $result = mysql_query($query);
  
  $row = mysql_fetch_array($result);
  
  return $row;
}
   
$product = find_product();

echo $product['title'].'<br/>';
  
    
    
    

?>

 

 

I know that is something dumb that I am missing but I am at my wits end trying to figure it out today.

 

Here is the error I continue to get:

 

Fatal error: Cannot redeclare find_products() (previously declared in /home/public_html/products/db_fns.php:53) in /home/public_html/products/db_fns.php on line 81
Link to comment
https://forums.phpfreaks.com/topic/189226-shopping-cart-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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