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