Jump to content

data not transferred to database


mindapolis

Recommended Posts

Can I get some help in figuring out why information isn't being transferred to the database? I have checked and all the form variables matched and it 's connected to the database just fine. Are there any other things to look for? here's the code.

 

$state = $_POST['state'];
$payment = $_POST['payment_Method']; 
$breed = $_POST['breed'];
$ship_state=$_POST['Shipstate']; 
//mysql_select_db("auntievics"); 
mysql_query("INSERT INTO customers (fname, lname, address, city, state, zip, phone, fax, email, re_enter_email, payment_Method, paypal_username, ship_first_name, ship_last_name, ship_address, ship_city, ship_state, ship_zip, ship_email, ship_re_email, pet_name, age, breed, nutritional_needs, special_instructions, product_name, quantity, price, sales_tax, subtotal, shipping_cost, total)
VALUES ('$fname', '$lname', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$payment', '$paypal_username', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$nutritional_needs', '$special_instructions', '$product_name', '$quantity', '$price', '$sales_tax', '$subtotal', '$shipping_cost', '$total')"); 

Link to comment
Share on other sites

are you getting any error?

is any of your $_POST variables null?  // in addition those should be sanitized

 

echo your raw query and check is it is correct.... to do that move your query string out of mysql_query()

 

$query = "INSERT INTO customers (fname, lname, address, city, state, zip, phone, fax, email, re_enter_email, payment_Method, paypal_username, ship_first_name, ship_last_name, ship_address, ship_city, ship_state, ship_zip, ship_email, ship_re_email, pet_name, age, breed, nutritional_needs, special_instructions, product_name, quantity, price, sales_tax, subtotal, shipping_cost, total)
VALUES ('$fname', '$lname', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$payment', '$paypal_username', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$nutritional_needs', '$special_instructions', '$product_name', '$quantity', '$price', '$sales_tax', '$subtotal', '$shipping_cost', '$total')";

//Echo raw query and check for any visible error
echo $query;

// execute your query string... adding at least some basic error trap
mysql_query($query) or die("Query Error : " . mysql_error());

Link to comment
Share on other sites

when I add that I get Query Error : Query was empty

 

here 's the thing.  I have 2 forms on the website, one is on the catalog page where you pick the product and quantity.  Upon clicking enter you go to the check out page.  When I added the suggested code on the check out page, and if I select a product from the product page and click proceed to check out I get Query Error : Query was empty.  Here 's the code for the product page. 

 

<?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>Untitled Document</title>
<style type="text/css">
td {
border-top-style: solid; 
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
border-top-color: #30C;
border-right-color: #30C;
border-bottom-color: #30C;
border-left-color: #30C;
}
#productCatalog {
width:400px;   
margin-right: auto;
margin-left: auto;
}
</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"; 
        $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\">{$row['product_title']}.<br /><br />{$row['product_Description']}.<br /> Price:  \${$row['price']}{$row['pricePer']}.<br /><br />Quantity <input name=\"quantity\" type=\"text\" size=\"2\" /></td></tr>";
        }
		echo "<tr>"; 
		echo "<td><input name=\"submit\" type=\"submit\" value=\"Proceed to Checkout\" />"; 
	echo "</table>";    
	echo "</form>"; 
echo "</div>";
footer();
?>
</body>
</html>

Link to comment
Share on other sites

what exactly is the error?

Query Error : Query was empty.

what this means?

 

in any of your posted code I can see were are you defining the variables used here:

VALUES ('$fname', '$lname', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$payment', '$paypal_username', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$nutritional_needs', '$special_instructions', '$product_name', '$quantity', '$price', '$sales_tax', '$subtotal', '$shipping_cost', '$total')";

 

again... echo your raw query and analyze from there.

Link to comment
Share on other sites

echo your raw query

 

in this way:

echo "My raw query is : " . $query;  // POST back the result of this line

 

Where in your code are you defining the values for the variables used in this line?... echoing your raw query will show you if all of them have a valid value or not, hence if your query is valid or not.

VALUES ('$fname', '$lname', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$email', '$re_enter_email', '$payment', '$paypal_username', '$ship_first_name', '$ship_last_name', '$ship_address', '$ship_city', '$ship_state', '$ship_zip', '$ship_email', '$ship_re_email', '$pet_name', '$age', '$breed', '$nutritional_needs', '$special_instructions', '$product_name', '$quantity', '$price', '$sales_tax', '$subtotal', '$shipping_cost', '$total')";

 

more clear?

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.