PDA

View Full Version : only some variables returning with $_POST


swissbeets
06-26-2008, 08:17 PM
for some reason the only values being put into my data base are position, image , and description. I have done test pages by assigning values to the variables on the page and they are imported fine so i am assuming it has to be a problem getting the information from the form here is my form


<form action="create_product.php" method="post">
<p>Product name:
<input type="text" name="Product Name" value="" id="Product_name" />
</p>
<p>Position:
<select name="position">
<?php
$product_set = get_all_products();
$product_count = mysql_num_rows($product_set);
$product_count + 1;// b/c we are adding a subject
for($count=1; $count <= $product_count+1; $count++) {
echo "<option value=\"{$count}\">{$count}</option>";
}
?>
</select></p>
<p>Product type:
<input type="text" name="Product Type" value="" id="Product_type" />


</p>
<p>Product Price:
<input type="decimal" name="Product Price" value="" id="Product_price" />


</p>
<p>Product Description:
<input type="text" name="Product description" value="" id="Product_description" />


</p>
<p>Product Image (Location):
<input type="text" name="Product image" value="" id="Product_image" />


</p>
<input type="submit" value="Add Product" />

these values are then referenced here

$position = mysql_prep($_POST['position']);
$Product_name = mysql_prep($_POST['Product_name']);

$Product_type = mysql_prep($_POST['Product_type']);
$Product_description = mysql_prep($_POST['Product_description']);
$Product_price = mysql_prep($_POST['Product_price']);
$Product_image = mysql_prep($_POST['Product_image']);

(mysql prep is making sure there is no malicious info like@$%&^%&*)
then it is put in the table here

$query = "INSERT INTO products (
position, Product_name, Product_type, Product_price, Product_description, Product_image
) VALUES (
'{$position}', '{$Product_name}', '{$Product_type}', '{$Product_price}', '{$Product_description}', '{$Product_image}'
)";
$result = mysql_query($query, $connection);
if ($result) {
// Success!
redirect_to("content.php");
} else {
// Display error message.
echo "<p>Product creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";

it is running correctly but simply not putting values into half of my table. this problem has been killing me, any help would be greatly appreciated

lux
06-26-2008, 08:37 PM
you don't need the curly braces around the vars in the sql statement

'{$Product_description}' should be '$Product_description'

is the value you are entering is numeric then you don;t have '' around the var

'$Product_price' should be $Product_price

after those changes if it doesn't work what errors messages appear (if any)??

davidj
06-26-2008, 08:41 PM
i was going to say that

swissbeets
06-26-2008, 09:00 PM
nothing should change on the form right?

i did all those changes, this is now my information

$query = "INSERT INTO products (
position, Product_name, Product_type, Product_price, Product_description, Product_image
) VALUES (
'$position', '$Product_name', '$Product_type', $Product_price, '$Product_description', '$Product_image'
)";
$result = mysql_query($query, $connection);
if ($result) {
// Success!
redirect_to("content.php");
} else {
// Display error message.
echo "<p>Product creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}



i entered the names of the product (name, type,description, etc)

this is the error i came up with

Product creation failed.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'description', 'location' )' at line 4

lux
06-26-2008, 09:30 PM
to help see whats going wrong echo the query string to see what the sql statement looks like.


$query = "INSERT INTO products (
position, Product_name, Product_type, Product_price, Product_description, Product_image
) VALUES (
'$position', '$Product_name', '$Product_type', $Product_price, '$Product_description', '$Product_image'
)";

echo $query;


look through the statement and see if you can spot any mistakes

swissbeets
06-26-2008, 09:49 PM
INSERT INTO products ( position, Product_name, Product_type, Product_price, Product_description, Product_image ) VALUES ( '1', '', '', , 'description', 'location' )Product creation failed.
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'description', 'location' )' at line 4






i cannot find any mistakes in the syntax and it looks like the data is just not even being sent from the form.... in the error nothing is being shown for those values any ideas?

lux
06-26-2008, 09:57 PM
you've got your name elements in the input fields wrong


<input type="text" name="Product Type" value="" id="Product_type" />
</p>
<p>Product Price:
<input type="decimal" name="Product Price" value="" id="Product_price" />
</p>
<p>Product Description:
<input type="text" name="Product description" value="" id="Product_description" />



try this:


<input type="text" name="Product_type" />


</p>
<p>Product Price:
<input type="decimal" name="Product_price" />

</p>
<p>Product Description:
<input type="text" name="Product_description" />

swissbeets
06-26-2008, 10:29 PM
wow thank you