php - Syntax issue UPDATE works but not INSERT -


i have dropdown lists default value selected. if there value there if statements allow update data. if no value instead whole row inserted. works if hard code third value 1. when set $category_of_taxom1 insert doesn't work. update works fine, if manually create record within db, can update via update sql shown below. if try insert no luck? (i have hard coded first 3 items inserted, third should variable mentioned above.

i have select list

      <select name="categoryselect1fromdb" > <option value ="">empty</option>';       <option value="1" <?php echo ($category_of_taxom1 == 1)?"selected":""; ?>>a</option>       <option value="2" <?php echo ($category_of_taxom1 == 2)?"selected":""; ?>>b</option>       <option value="3" <?php echo ($category_of_taxom1 == 3)?"selected":""; ?>>c</option>       <option value="4" <?php echo ($category_of_taxom1 == 4)?"selected":""; ?>>d</option> </select>  

and set of statements.

  if(isset($_post['save']))  {                     $category_of_taxom1 = $_post['categoryselect1fromdb'];                   $number_of_taxom1 = $_post['number_of_taxom1'];   if (!empty($category_of_taxom1)){ //this value fromdb if not empy below else last              pg_query("update record_tbl set category_of_taxom ='$category_of_taxom1', number_of_taxom ='$number_of_taxom1' sheet_id = '$sheet_id' , line = 1");             echo "updated!";      } else              {              pg_query("insert record_tbl (line, taxom_id, category_of_taxom, number_of_taxom, sheet_id) values (1,1,'$category_of_taxom1','$number_of_taxom1','$sheet_id')");              echo "new record ?saved!"; } }    

this example of working pgsql line use else in site:

  $sql8 = "insert record_tbl (line, taxom_id, category_of_taxom, number_of_taxom, sheet_id) values (8,8,'$_post[gammarus_numbers]','$_post[countgammarus]','$sheetid')";   $result = pg_query($sql8); 

the datatype field 'category_of_taxom' set varchar, meaning should have quotes around value when using insert. can either:

1) change datatype of category_of_taxom integer in database

2) include quotes around value in insert statement:

('1','1','1','$number_of_taxom1',$sheet_id) 

related documentation: mysql - quote numbers or not?


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -