Jump to content

data not transferring


mindapolis

Recommended Posts

hi, I have a webpage that is driven by a database mostly.  it has a catalog of dog treats and most will transfer to the checkout page but 2 two won't.  I have checked the database and everything looks fine if it would help, here 's the webpage.  http://auntievics.com/treats.php.  it's the Cara The Flirt's K9 Canoli Stuffed and the Cara The Flirt's K9 Canoli Unstuffed that won't transfer.  Any help would be appreciated. 

Link to comment
Share on other sites

<?php

session_start();
if(!isset($_SESSION['quantity']))
{
  $_SESSION['quantity']=array(); //if there are no quantities selected, the array is empty
  if(is_array($_POST['quantity']))//if there are items in the cart
{
  echo $quantity;
  header("location: checkOut.php");
}
}
require_once("functions.php");
?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Auntie Vic's products </title>
<meta name="keywords" content="Dog treats, organic dog treats, dog food, dog allergies,  Indiana" />
<meta name="description" content="Check out the many dog treats that can be ordered for dogs who may or may not have allergies!   " />
<style type="text/css">
td {
padding-bottom:20px; 
}
#productCatalog {
width:410px;   
margin-right: auto;
margin-left: auto;
}
#disclaimer {
background-color: #666633;
padding:10px; 
}
</style>

<link href="doggyTreats.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
logo();
navBar(); 
echo "<div id=\"productCatalog\">";
echo "<form action=\"checkOut.php\" method=\"post\" name=\"catalog\">";

DatabaseConnection();  

  $query = "SELECT * FROM treats WHERE productType = 'regular'"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0;
        echo "<table>";
        while ($row = mysql_fetch_array($result_set))
        {
		echo '<tr><td width="200px"><img src="'.$row['product_pic'].'" /></td><td width="200px"><b>'.$row['product_title'].'</b><br />'.$row['product_Description'].'<br /> Price:  $'.$row['price'].$row['pricePer'].'<br /><br />Quantity <input name="quantity'.$row["product_id"].'" type="text" size="2" /></td></tr>';
        }
		echo "<tr>"; 
	echo "<td colspan = '2'>  SPECIALITY TREATS </td>";
  $query = "SELECT * FROM treats WHERE productType = 'specialty'"; 
        $result_set = mysql_query($query) or die(mysql_error());
$i = 0; 
	        while ($row = mysql_fetch_array($result_set))
        {
		echo '<tr><td width="200px"><img src="'.$row['product_pic'].'" /></td><td width="200px"><b>'.$row['product_title'].'</b><br />'.$row['product_Description'].'<br /> Price:  $'.$row['price'].$row['pricePer'].'<br /><br />Quantity <input name="quantity'.$row["product_id"].'" type="text" size="2" /></td></tr>';
        }
//end of catalog 		
	echo "<tr>"; 	
	echo "<td id = 'disclaimer' colspan = '2'> Auntie Vic carefully researches all recipes on this site. All of them are taste tested and tried by various dogs. However, there is always a possibility some dogs will have a food intolerance and we cannot be held liable in this case. These treats are treats meant for special occasions, celebrations and the simple enjoyment of giving your dog a little extra something. They should not be used to replace a properly balanced meal. Always ask your vet for advice before adding homemade treats to any diet. </td>"; 

	echo "</tr>"; 
	echo "<tr>"; 
	echo "<td><input name=\"ProceedToCheckout\" type=\"submit\" value=\"Proceed to Checkout\" /></td>"; 
		echo "</tr>"; 
	echo "</table>";    
	echo "</form>"; 
echo "</div>";
footer();
?>
</body>
</html> 

Link to comment
Share on other sites

okay, I deleted that field, added a product_id field, tried to make that the primaries key with auto incredimnt and its saying

SQL query:

 

ALTER TABLE `treats` CHANGE `product_id` `product_id` INT( 3 ) NOT NULL AUTO_INCREMENT

 

MySQL said: Documentation

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

 

in this table  there should not be any other auto increment fields. 

Link to comment
Share on other sites

I have no idea what your DB Table looks like, nor your server side code, but this is how I do things:

 

Small example table and getting to the meat.

+-------------+---------------+-----------------+------------------+
|  product_id  |  product_name  |  product_desc  |  product_cost_ per |
+-------------+---------------+-----------------+------------------+
|      1        |  Bo's Chunky...   |  Whole whea... |  $10.00 / lb        |
|      2        |  Miss Cuddles...  |  Unbleached ... |  $10.00 / lb        |

<?php
    // Retrieve the data
    $products = (your querying method);  

    // Ensure successful query
    if( $products): 
?>
       // Since our query was successful, we can open our form
        <form method="POST" action="la-la-land.php" />

 

Now, you write one code block which iterates through all of your products.

<?php foreach ( $products as $product ):  ?>
         <section class="dog_treats" data-treat=" <?php echo $product->product_id; ?> ">
            <h3><?php echo $product->product_title; ?></h3>
            <div>
               <?php echo $product->product_desc; ?>       <br />
                <?php echo $product->product_cost_per; ?>  <br />
                <input type="text" name="treats[ <?php echo $product->product_id; ?>  ]" />
            </div>
         </section>
<?php endforeach; ?>

I would accept the input as an array so it makes it easier to deal with them on the opposing end.

 

 

After each treat section has been crafted, close out the form

<input type="submit" name="submit" value="buy my stuff" />
</form>
<?php endif?>

 

The receiving script:

<?php 
    if( isset($_POST['submit'] )
    {
        foreach( $_POST['treats'] as $treat )
        {
            // Process handling here
        }
    }
?>

 

Link to comment
Share on other sites

I did what you guys said to do so how do I fix it?

 

Thinking about the meaning of what you are doing is required in programming, because computers only do exactly what their code and data tells them. I'm not trying to pick on you or be mean, but you must think about what goal you are trying to achieve and how it relates to your code and data.

 

A statement that - "your product_id should be the auto-increment identifier from your database table, not a text string." is a suggested direction that requires more than one step to accomplish (all programming involves breaking down a problem into the individual steps needed to accomplish any task.)

 

1a) If you didn't already have an auto-increment column, you would need to add one to your table. Are you sure you didn't already have an auto-increment column with values in it? Most database management tools will automatically make the first column you create an auto-increment index.

 

2a) If you had to added an auto-increment column, you will now need to assign numerical id values (1,2,3,...) to your existing products and setup the table so that it will use the next available auto-increment value when you insert new rows (the database might do this for you after you assign values to the column.) Given that you have a relatively small number of products in your table, I would manually assign the numerical id values to your existing products using your favorite database management tool (phpmyadmin or similar.) To set the next available auto-increment value, you would directly execute a query like: ALTER TABLE your_table_name AUTO_INCREMENT = x; where x is the value you want the table to use for the next row that gets inserted.

 

3) Now that you have an exiting or a newly added auto-increment column in the table, with values in it, you would just need to use that column name in your queries.

 

 

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.