Jump to content

Do not allow duplicate product


tonnybarros

Recommended Posts

Guys, I need help again.

 

I'm using the API code below to add custom product on my other site.

Works already tested.

 

But I must not be allowed the same product be added.

I would like to create something that check the product name so that it is not added again?

 

advance thank you for your assistance

 

 

$url = "https://www.meusite.com.br/includes/api.php";
$postfields["username"] = "user"; # Admin username goes here
$postfields["password"] = md5("pass"); # Admin password goes here  
$postfields["action"] = "addproduct";
$postfields["type"] = "other";
$postfields["gid"] = "18";
$postfields["name"] = $item[item];
$postfields["module"] = "MyModule";
$postfields["paytype"] = "onetime";
$postfields["pricing[1][monthly]"] = $valores; 
$postfields["description"] = $item[live_preview_url];
$postfields["order"] = "100";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

Link to comment
Share on other sites

I'm trying to create, it seems to work well.

Does anyone disagree?

 

require("init.php");
$produto = "Produto Teste";
$sql = "SELECT * FROM tblproducts WHERE name = '$produto'";
$query = mysql_query($sql);
$num_rows = mysql_num_rows($query);

if($num_rows == 0)
{
echo "Nao Existe";
}
else
{
echo "Ja existe";
}

Link to comment
Share on other sites

Solved with the code above, who needs that can use the example below.

 

require("init.php");
$produto = "Produto Teste";
$sql = "SELECT * FROM tblproducts WHERE name = '$produto'";
$query = mysql_query($sql);
$num_rows = mysql_num_rows($query);

if($num_rows == 0)
{
//The product does not exist, place the api here
}
else
{
//Product already exists, do nothing, or put some warning message here
}

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated