mysql - $http(req) entering into success even though query string not making entry in DB - AngularJS -


this addnewproduct function.

productservice.addnewproduct = function(newproduct)  {      //alert (json.stringify (newproduct));      var req = {         url: "cgi-bin/addnewproduct.pl",         method: 'get',         params: {productid: newproduct.productid, productname: newproduct.productname, productimagepath: newproduct.productimagepath, brandid: newproduct.brandid, subcategoryid: newproduct.subcategoryid}         //params: { newproduct: productdata }     };      $http(req).success(function(data, status, headers, config)     {         productlist.unshift(newproduct);         //alert (data);         alert ('new product added!');     })     .error(function()     {         alert ('new product add error!');     });  } 

this addnewproduct.pl

    #!c:/perl64/bin/perl.exe  use strict; use warnings; use dbi; use cgi::carp qw(warningstobrowser fatalstobrowser); use cgi; use cgi::cookie; use cgi::session qw(); use json;  print "content-type: text/html\n\n";  $cfg = "config.pl"; $db_handle = dbi->connect ("dbi:mysql:$cfg->{database}", $cfg->{user}, $cfg->{password} ) or die "couldn't connect database: $dbi::errstr\n";  $cgi = cgi->new(); #my $decodeddata = decode_json($cgi->param("newproduct"));  $product_id = $cgi->param('productid'); $product_name = $cgi->param('productname'); $product_description = 'desc'; $image_path = $cgi->param('productimagepath'); $brand_id = $cgi->param('brandid'); $subcatty_id = $cgi->param('subcategoryid');  $sql_query = "insert table_products values ($product_id, '$product_name', '$product_description', '$image_path', '$brand_id')"; $statement = $db_handle->prepare ($sql_query) or die "couldn't prepare query '$sql_query': $dbi::errstr\n";   $statement->execute() or die "sql error: $dbi::errstr\n";     $db_handle->disconnect; #print $cgi->header; 

this table structure.

mysql> describe table_products; +---------------------+--------------+------+-----+---------+-------+ | field               | type         | null | key | default | | +---------------------+--------------+------+-----+---------+-------+ | product_id          | int(11)      | no   | pri | null    |       | | product_name        | varchar(64)  | no   |     | null    |       | | product_description | varchar(64)  | no   |     | null    |       | | product_image_path  | varchar(128) | no   |     | null    |       | | brand_id            | int(11)      | no   |     | null    |       | | available           | tinyint(1)   | no   |     | null    |       | +---------------------+--------------+------+-----+---------+-------+ 

please note in query string missing value available field. means entry wont created in table using query string.

but after $http(req), getting alert ('new product added.').

why so? when entry not created in perl should enter in error. missing , how fix these kind of errors?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -