i have code insert data comes while, in db. i'm trying use jquery serializearray , jquery post together. seems errors
$query= "select * barcode_prodotti"; $result = mysql_query($query) or die(mysql_error()); while($row=mysql_fetch_array($result)){ echo' <input type="text" name="prodotto[]" class="prodotto" value="'.$row["prodotto"].'"></div> <input type="text" name="prezzo[]" class="price" value="'.$row["prezzo"].'"> <input type="text" name="quantita[]" class="price" value="'.$row["quantita"].'">'; } ?> <script src="js/mine.js"></script> <button>serialize form values</button> </form> <div id="results"></div>
this jquery code put in mine.js
$(document).ready(function(){ $('form').submit(function(msg) { var mia =$(this).serialize(); $('#results').text(mia) alert($(this).serialize()); // check show form data being submitted $.post("testtest.php",$(this).serializearray(),function(data){ alert(data); }); return false; }); });
this php file (testtest.php)
mysql_connect("localhost","root",""); mysql_select_db("db"); $arr = $_post; $sql="insert table values( '".$arr['prodotto']."', '".$arr['quantita']."', '".$arr['prezzo']."' )"; $rssql = mysql_query($sql); ?>
so serialize ok (i tried assign in div value see if ok), can't insert values in db
your insert
query ends looking after variable substitution.
insert table values( 'product', '123', '321')
if table
has 3 columns work fine. otherwise fail. may wish use query instead.
insert table (prodotto, prezzo, quantita ) values( 'product', '123', '321')
which enumerates columns want data.
after doing insert (and after query) should check errors. can done code this.
$res = mysql_query($q); if ($res === false) { echo $mysql_error (); }
note well: mysql_xxx()
interface being removed php reason: vulnerable cybercriminals. please adopt mysqli_xxx()
or pdo
possible.
Comments
Post a Comment