Karyna Posted August 15, 2011 Share Posted August 15, 2011 im driving mad with this... i know my code is right but i must be missing something i have no syntax errors, the page doesn´tn display any error...i must save in a database each item buy it by customers.... but no values are stored i believe the insert to statement must be some wrong the code i using is this num_rows was obtained by count the nmber of fields al fields are numeric except descrip and pictu are varchar for($i=0;$i<=count($estimate)-1;$i ++){ if($estimate[$i] != NULL){ $qty=$estimate[$i]['qty']; $descripp=$estimate[$i]['descrip2']; $ppictu=$estimate[$i]['pictu']; $pprice=$estimate[$i]['price']; $subt=$estimate[$i]['price']*$estimate[$i]['qty']; echo $i; <-- it displays each number correct so the value of $estimate its OK!! mysql_query("INSERT INTO estimates (numb, name, mail, qty, descrip, pictu, unit, stotal, gtotal,item) VALUES ($num_rows, '$_POST[name]', '$_POST[mail]', $qty, $descripp, $ppictu,$pprice, $subt, $total, $i);"); { ¨{ also try this with same result... $cuery='"'; $cuery.='INSERT INTO estimates (numb, name, mail, qty, descrip, pictu, unit, stotal, gtotal,item) VALUES (' ; $cuery.="'"; $cuery.= '$num_rows'; $cuery.="', "; $cuery.="'"; $cuery.='$_POST[name]'; $cuery.= "', '"; $cuery.= '$_POST[mail]'; $cuery.= "', '"; $cuery.= '$qty'; $cuery.="', "; $cuery.='"$descripp", '; $cuery.='"$ppictu", '; $cuery.= "'"; $cuery.= '$pprice'; $cuery.="', '"; $cuery.='$subt'; $cuery.="', "; $cuery.='$total'; $cuery.="', "; $cuery.='$i'; $cuery.=');'; $cuery.='"'; mysql_query("$cuery"); Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/ Share on other sites More sharing options...
AyKay47 Posted August 15, 2011 Share Posted August 15, 2011 your concatentation is giving me a headache trying to decipher.. use this mysql_query("$cuery") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257777 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Share Posted August 15, 2011 $cuery.= '$qty'; $cuery.="', "; <- ' missing $cuery.='"$descripp", '; check aii your single quotation mark. Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257779 Share on other sites More sharing options...
mikosiko Posted August 15, 2011 Share Posted August 15, 2011 step # 1 echo you raw query and analyze it . your $cuery intent is just nonsense... throw it.. some others observations: 1) sanitize your POSTed variables before use them in the query, otherwise you are open to attacks. and also check how you are using the apostrophes on them. 2) Query in a loop.... in general no good idea... you can use the form INSERT INTO table_name (column_names...) VALUES (1st set of values), (2nd set of values), etc..etc)... Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257783 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Share Posted August 15, 2011 This will help full to you PHP MySQL Insert Into http://www.w3schools.com/php/php_mysql_insert.asp Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257787 Share on other sites More sharing options...
AyKay47 Posted August 15, 2011 Share Posted August 15, 2011 This will help full to you PHP MySQL Insert Into http://www.w3schools.com/php/php_mysql_insert.asp Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257789 Share on other sites More sharing options...
chintansshah Posted August 15, 2011 Share Posted August 15, 2011 php parse ' quote as a string. So use concatenation in Insert query. Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257797 Share on other sites More sharing options...
Karyna Posted August 15, 2011 Author Share Posted August 15, 2011 heyyy tnx to all.... i finally get it ... with a litle of ur answers... hughss!! Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257812 Share on other sites More sharing options...
voip03 Posted August 15, 2011 Share Posted August 15, 2011 AyKay47 ? Quote Link to comment https://forums.phpfreaks.com/topic/244849-php-dont-insert-values-in-database-mixed-types/#findComment-1257822 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.