Skip to content Skip to sidebar Skip to footer

How To Submit Jquery Add Rows Data To Mysql Using Php

So I have this piece of code I've been tinkering with. The Jquery is modified from somewhere else. I'm wanting to be able to add products on this page (which currently works)... bu

Solution 1:

I've noticed few mistakes that you've made in your code.

The first mistake is:

<select name="'product1'" id="product1">

Remove single quotes from the value of name attribute and it should look like:

<select name="product1" id="product1">

This is not considered an issue. If you were using single quotes around the value of name attribute, it would be quite annoying to access its value in PHP.

So, you would need to use complex expression to fetch the value like the following syntaxes:

$_POST['\'product1\'']

$_POST["'product1'"]

The first one uses escape sequence of backward slash to escape single quotes.

The second one uses double quotes to access keys with single quotes wrapped around. This one is relatively easier than the first one involving a bit complex expression.

The second mistake is:

The last three HTML elements below the form tag are not wrapped inside the form. The two among the last three elements which are submit and hidden element belong to form element. After modifying the code, the whole code should be like the following:

<formmethod="POST"action="invoicereg.php"id="data"name="sub">
    product:
    <selectname="product1"id="product1" ><optionvalue="aclt">Tobacco</option><optionvalue="aed">Energy Drink</option></select>
    nicotine:
    <selectname="nicotine1"id="nicotine1"><optionvalue="3">3mg</option><optionvalue="6">6mg</option><optionvalue="12">12mg</option></select>
    Qty:<inputtype="text"id="qty"name="qty"></input><br><buttontype="submit"form="data">SUBMIT</button><inputtype="button"id="addnew"name="addnew"value="Add new item" /><inputtype="hidden"id="items"name="items"value="1" /></form>

Hope it helps!

Solution 2:

Make your input type submit button

<button type="submit" form="data">SUBMIT</button>

to

 <inputtype="submit" form="data" value="SUBMIT">

Post a Comment for "How To Submit Jquery Add Rows Data To Mysql Using Php"