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 :
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.