Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

about php, but I don't know how to make it check whether the product already exists or not

I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help
I have problem cant exist catogaries :
I want chek if the catogary is add before or not
please i need help

<?php
require '0.php';
if (isset($_POST['login'])){
  $catogary_name = $_POST['catogary-name'];
  $catogary_much = $_POST['catogary-much'];

  
  if (empty($catogary_name) == true || empty($catogary_much) == true){
  

  }else{
   
  

    
    
        $sql = "insert into catograyies (CATOGRARY,howMush) VALUES (' $catogary_name','$catogary_much')";
    
        
    
    
    
    if ($sq->query($sql) === TRUE) {
      
      } else {
        
      }  
  }
  header("location:");
  exit;
}

?>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use a SELECT query first to check if the category already exists.

<?php
require '0.php';
if (isset($_POST['login'])){
    $catogary_name = $_POST['catogary-name'];
    $catogary_much = $_POST['catogary-much'];
  
    if (empty($catogary_name) == true || empty($catogary_much) == true){
    }else{
        $stmt = $sq->prepare("SELECT 1 FROM catograyies WHERE CATOGRARY = ?");
        $stmt->bind_param("s", $catogary_name);
        $stmt->execute();
        $result = $stmt->get_result();
        if ($result->num_rows > 0) {
            echo "Category $catogary_name already exists";
        } else {
            $stmt = $sq->prepare("insert into catograyies (CATOGRARY,howMush) VALUES (?, ?)");
            $stmt->bind_param("ss", $catogary_name, $catogary_much);
            if ($stmt->execute()) {
            } else {
            }
        }
    }
    header("location:");
    exit;
}
?>

I’ve also shown how to use prepared statements instead of substituting variables into the SQL, to protect against SQL-injection.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading