0

I have a (subject) and (page) TABLES in a database.

page TABLE belongs to subject TABLE, each subject has an ID

When user click on a subject mysite/blog?subject=(ID gets set__) 1,2,3,4,5

So i want pages to be INSERTED according to in which subject they are in URL.

Well, i'm sending data using POST form to a (form_process.php) page.

<?php       
     if(isset($_POST["submit"])){
         $Message = $_POST["Content"];

         $query  = "INSERT INTO page ";
         $query .= "(Message, SubjectID) ";
         $query .= "VALUES ('{$Message}', $_GET['subject'])";
         $result = mysqli_query($connection, $query);

         if(mysqli_affected_rows($connection) > 0){
           echo "Page added to its beloging subject";
         }
     }
?>

I get this error:

Notice: Undefined index: subject in C:\xampp\htdocs\kerimgrozny\public\blog.php on line 64

The problem is: when using $_GET variable in INSERT query as FOREIGN KEY, It gets undefined.

The link on GitHub: https://github.com/kerimgrozny/kerimgrozny.git

Kerim Tim.
  • 1,159
  • 12
  • 13

1 Answers1

0

replace

$query .= "VALUES ('{$Content}', {$subject} )";

by

$query .= "VALUES ('{$Content}', '{$subject}' )";

Hope it help you.

J Ha
  • 1,202
  • 13
  • 16