-3

I got this error while I run my PHP page in Postman. I don't know what mistake I did.

Here, I am trying to insert the id of the workordername into the ticket_raising table.

work_order_id is the foreign key in the ticket_raising table.

Here is my PHP code

<?php
require 'connection.php';
$workordername = $_POST["workordername"];
$workorderid = mysqli_query($conn,"select `work_order_id` from `workorder_category` where `workorder_name` = '$workordername'");
$submitted_on = $_POST["submitted_on"];
$status = $_POST["status"];
$subject = $_POST["subject"];
$notes = $_POST["notes"];


$mysql_query = "insert into ticket_raising(work_order_id,submitted_on,status,subject,notes) values ('$workorderid','$submitted_on','$status','$subject','$notes') ";
if ($conn->query($mysql_query)==TRUE) {
    echo "insert successfully";
}
else {
    echo "error:".$mysql_query."<br>".$conn->error;
}
$conn->close();
 ?>

I am adding table schemas of ticket_raising and workorder_category here. https://i.stack.imgur.com/fjg9j.png and https://i.stack.imgur.com/vsRLh.png

Any suggestive examples for inserting the foreign key into the table that would make my learning easier.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Chandu
  • 1
  • 4

1 Answers1

1

You try to insert into field work_order_id but your scheme image shows field name word_order_id.

Seems like a typo when you created the field name?
ie
Schema is: worD_order_id
SQL is: worK_order_id

So you either need to update your scheme to change it to work_order_id or change your code to insert into word_order_id. If you change the scheme you'll have to change all scripts where this field name is currently referenced.

James
  • 4,644
  • 5
  • 37
  • 48