Adnan D.
Adnan D.

Reputation: 440

PHP is updating instead of inserting

I am creating a page where the user fill a report and that report is inserted to the database I have below my php page that is supposed to insert new values to table reports, but it is updating instead

<?php 
include 'connectionfile.php' ; 
$ref = $_POST['ref']; 
$title =$_POST['titl']; 
$type = $_POST['type']; 
$content = $_POST['content'];
session_start(); 
$sql = "insert into reports (reference, title,id_type, content) values ('".$ref."', '".$title."', '". $type."','".$content."');"; 
$result =mysqli_query($con,$sql ); ?>

Is it because id_type (primary key of table type) is a foreign key -in table report- of value 1 and 2?

Because if I insert id_type=1 for example, id_report (primary key of table report) increments by 1, same goes to id_type=2

Answer might be clear,my knowledge in web development was forgotten.

Upvotes: 1

Views: 90

Answers (1)

Richard
Richard

Reputation: 2815

With the SQL-Query you provided, no update is possible. You can make an UPDATE ON DUPLICATE KEY, but this is not in this query. Please note, that you do not have to and should not specify any value for an automatically setted parameter (AUTO_INCREMENT).

Upvotes: 2

Related Questions