mindapolis Posted December 9, 2011 Share Posted December 9, 2011 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')"); Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/ Share on other sites More sharing options...
mikosiko Posted December 9, 2011 Share Posted December 9, 2011 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()); Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296289 Share on other sites More sharing options...
mindapolis Posted December 9, 2011 Author Share Posted December 9, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296306 Share on other sites More sharing options...
mikosiko Posted December 9, 2011 Share Posted December 9, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296317 Share on other sites More sharing options...
mindapolis Posted December 9, 2011 Author Share Posted December 9, 2011 what? Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296325 Share on other sites More sharing options...
mikosiko Posted December 9, 2011 Share Posted December 9, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296337 Share on other sites More sharing options...
mindapolis Posted December 9, 2011 Author Share Posted December 9, 2011 it says Query Error : Query was empty Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296350 Share on other sites More sharing options...
fenway Posted December 9, 2011 Share Posted December 9, 2011 it says Query Error : Query was empty What's "it"? The words "Query Error" do not show up in your code. If you can't echo a string in php, then we really can't help you. Quote Link to comment https://forums.phpfreaks.com/topic/252839-data-not-transferred-to-database/#findComment-1296373 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.