0

in the insert category I am typing fruits to insert but nothing is happening, and in
phpmyadmin the result is also not showing please help I have written the code in connect.php and inserted the category same as yours but nothing is happening it's just reloading please help.

<?php

include('../includes/connect.php');

if (isset($_POST['insert_cat'])) 
{

 $category_title = $_POST['cat_title'];
  $insert_query= "Insert into 'categories' (category_title) Values ('$category_title')";
  $result = mysqli_query($con,$insert_query);
  if ($result) {
    echo "<script> alert('Category has been added')</script>";
  }

}

?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Categories</title>
</head>
<body>
<form method="POST" action="" class="mb-2">
  
<div class="input-group w-90 mb-3">
  <div class="input-group-prepend">
    <span class="input-group-text bg-info" id="basic-addon1">
      <i class="fa-solid fa-receipt"></i>
    </span>
  </div>
  <input type="text" class="form-control" name="cat_title" placeholder="Insert Categories">
</div>

<div class="input-group w-10 mb-3 m-auto">

  <input type="submit" class="bg-info border-0 p-2" name="insert_cat" placeholder="Insert Categories" value="Insert Categories">
  
</div>
</form>
</body>
</html>
  • Table names should be surrounded by backticks, if they need to be quoted at all. Using single quotes will turn it into a value and break your query. – aynber Sep 14 '22 at 18:56
  • Thanks aynber. You sort out my problem – Danyal Samad Sep 14 '22 at 18:58
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/32391315) – Dharman Sep 14 '22 at 19:13

0 Answers0