Jump to content

php dont insert values in database mixed types


Karyna

Recommended Posts

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");

Link to comment
Share on other sites

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)...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.