Jump to content

Updating MYSQL Data via PHP Webservice Call


Recommended Posts

Hello, I'm hoping someone may be able to help me.


I have a php shopping cart (zen cart to be exact) and I have a web service that someone helped me write to allow retrieval of data from the MYSQL database to be used by an external website built in .net (I am a .net developer).


Anyway, the current web service only allows "reading" of data which is working fine, however now I would like to add an extra function that would allow the external site to update the stock levels in the Zen Cart's mysql database via a web service call.


This is what I have curently : 

require 'includes/configure.php';
class stephin 

	function __construct($hostname,$dbuser,$dbpass,$dbname) {
		global $config; 
		if(!$this->dblink) {
					return $this->dblink;
					die("Database cant be selected.");
					return false;				
				die("No database connection");
				return $this->dblink;
			return $this->dblink;

	function select($query){
		if($result3 > 0){
					$result[] = $row;
			return $result;
		return false;
$data=$db->select("select zen_products_description.products_id,zen_products.products_model,zen_products_description.products_name,zen_products.products_status,zen_products.products_price,zen_products.products_quantity,zen_products.products_weight,zen_products.product_is_always_free_shipping as free_shipping,zen_products.products_sort_order as sort_order,zen_products.master_categories_id as categories_id,zen_products_description.products_description,zen_products.products_image  from zen_products_description inner join zen_products on zen_products.products_id= zen_products_description.products_id  where zen_products.products_id=$id");
$data=$db->select("select zen_products_description.products_id,zen_products.products_model,zen_products_description.products_name,zen_products.products_status,zen_products.products_quantity,zen_products.products_price,zen_products.products_weight,zen_products.products_sort_order as sort_order,zen_products.master_categories_id as categories_id  from zen_products_description inner join zen_products on zen_products.products_id= zen_products_description.products_id order by zen_products_description.products_id");
echo json_encode($data);

I have figured out that I will need something like this:

$prod_id = $_GET['prod_id'];
$prod_qty = $_GET['prod_qty'];

$sql = "UPDATE zen_products SET products_quantity = $prod_qty WHERE products_id = $prod_id" ;

$retval = mysql_query( $sql, $conn );
if(! $retval )
  die('Could not update data: ' . mysql_error());
echo "Updated data successfully\n";

But I am just not sure how to glue it together with the existing code I have.


In addition I would also like to make sure that the quantity cannot be updated to a value less than zero.


Obviously I also have security issues to consider but I will worry about that once I can get this working.


Thanks in advance.

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.

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.