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
  • 1,101
  • 12
  • 12
  • Which line is line 64? – mfisher91 Sep 10 '15 at 08:48
  • $subject = $_GET[subject]; $query .= " VALUES ('{$Message}', {$subject} )"; – Kerim Sep 10 '15 at 08:50
  • Also, you haven't shown where you're using $_GET[subject] in the PHP code where you're doing the query... – mfisher91 Sep 10 '15 at 08:50
  • Have you tried echoing out $subject? I know you've tried $_GET['subject'], but it's worth checking if that's gone into $subject (I'm guessing it hasn't) – mfisher91 Sep 10 '15 at 09:04
  • Are the two code blocks from the same PHP file (blog.php)? Also, you should be worried about [SQL injection attacks](http://bobby-tables.com/php.html). – Anders Sep 10 '15 at 09:19

1 Answers1

0

replace

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

by

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

Hope it help you.

J Ha
  • 1,122
  • 12
  • 16