Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<?php
require('top.php');
if(isset($_POST['submit']))
{
    $catogry=$_POST['Catogry'];
    echo  $catogry;
    $add_catogry="INSERT INTO categories(id,categories, status) VALUES ('$catogry','1')";
    mysqli_query($conn,$add_catogry);
     
     header('location:catogry.php');
     die();
       
 }
?>
 same code for another work fine here also when i print the value of $catogry it will print the value which i have entered.
but not inserting in database..


What I have tried:

 same code for another work fine here also when i print the value of $catogry it will print the value which i have entered.
but not inserting in database..
</pre
Posted
Updated 11-Apr-21 3:45am

PHP
$add_catogry="INSERT INTO categories(id,categories, status) VALUES ('$catogry','1')";

Your INSERT is wrong because there is 3 fields and only 2 values.

Not necessary a solution to your question, but another problem you have.
Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]
 
Share this answer
 
That is really poor code. You create an INSERT clause (which is missing a parameter), send it to the database, and do not bother to check whether it worked or not. So sometime in the future when you need to read that important information it will not be in your database. You must always check the status returned from all system calls in order to know whether your code is working.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900