0

I am trying to post a td from a form.

this is my td...

<td class="product'.$id.' " name="qnty" value="'.$value.'">'.$value.'</td>

since that has no input field, how i will post that value?

Because i am trying to post it like this, and it is not working.

if(isset($_POST['submit_post'])){

$fabric=$_POST['fabric'];
$size=$_POST['size'];
$qnty=$_POST['qnty'];

$ins_sql = "INSERT INTO orders (fabric,size,product_quantity) 
            VALUES ('$fabric', '$size' , '$qnty')";
if ($conn->query($ins_sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " ;
}
$conn->close();
}

The rest of the posts are from dropdowns and they are working fine. Why this is not working?

Error: Undefined index: qnty

James Allan
  • 280
  • 5
  • 18
  • 1
    `` are **NOT** form fields, have no `name` attribute, and are **NOT** submitted with a form. And you are vulnerable to [sql injection attacks](http://bobby-tables.com). – Marc B Oct 17 '16 at 21:13
  • i know, this is only test – James Allan Oct 17 '16 at 21:21
  • @MarcB this is not duplicated! i know what is a Undefined variable, i just was getting Undefined index : qnty because it was not a input name and just a td tag with the name`qnty` – James Allan Oct 18 '16 at 11:12
  • 1
    Yes, it's a dupe. The specifics may be different from person to person, but the core reason is ALWAYS the same. – Marc B Oct 18 '16 at 16:23

1 Answers1

2

Value will not work outside of form elements. You can make an input field and disable editing.

Or you can instead a hidden input.

 <td><input type="hidden" name="qnty" value="'.$value.'"/>'.$value.'</td>

If didn't understand the issue correctly it is because there is missing code here.

James Allan
  • 280
  • 5
  • 18