2
I’m creating an online store, and I need to add the products on the site through the comic book.
To make it easier, I want to create a graphical part, which is already done, but in my variables gives me the following error:
Notice: Undefined index: product_code in /home/i12184/public_html/admin.php on line 4
Notice: Undefined index: product_name in /home/i12184/public_html/admin.php on line 5
Notice: Undefined index: $product_desc in /home/i12184/public_html/admin.php on line 6
Notice: Undefined index: $product_img_name in /home/i12184/public_html/admin.php on line 7
Notice: Undefined index: price in /home/i12184/public_html/admin.php on line 8
My code:
$product_code = $_POST['product_code'];
$product_name = $_POST['product_name'];
$product_desc = $_POST['$product_desc'];
$product_img_name = $_POST['$product_img_name'];
$price =$_POST['price'];
$insert ='insert into products (product_code, product_name, product_desc, product_img_name, price)
Values("'.$product_code.'", "'.$product_name.'", "'.$product_desc.'",
"'.$product_img_name.'", "'.$price.'")';
mysql_query($insert);
Html
<form action="admin.php" method="post" onsubmit="formsubmit(this)">
Codigo do Produto: <input type="text" name="product_code" /><br /><br />
Nome do Produto: <input type="text" name="product_name" /><br /><br />
Descricao do Produto: <input type="tinytext" name="product_desc" /><br /><br />
Nome da Imagem do Produto: <input type="text" name="product_img_name" /><br /><br />
Preco: <input type="decimal" name="price" /><br /><br />
<input type="submit" value="Enviar">
</form>
<script>
function formsubmit(form)
{
form.submit();
}
</script>
For what you’re saying in your mistake
$_POST['product_code']
does not exist. Could post the result ofvar_dump($_POST)
?– Erlon Charles
@Erloncharles at the moment I can’t do it :/
– Pedro Pimenta
Could put part of the html form?
– rray
Could complement and add this your javascript method
formsubmit()
? Just to make it right:$_POST['$product_desc'];
note that you are using the $ in front of the name. And here too:$_POST['$product_img_name'];
. Take this $ and stay like this:$_POST['product_img_name']; $_POST['product_desc'];
– Rafael Withoeft
@Rafaelwithoeft done :) really hadn’t noticed the '$' thank you so much
– Pedro Pimenta
Was resolved:?
– Lollipop
Ja funciona Thanks to everyone simply move the php code to another file.
– Pedro Pimenta