0

I am having an undefined index: ISBN error when running the following code. I think it is because I don't have ISBN for the name of my select, but I only want one select. How can I solve this?

<select name="GroupID">
......
</select>

<?php
$GroupID=$_POST['GroupID'];
$ISBN=$_POST['ISBN']; 
?>
Jon
  • 215
  • 1
  • 3
  • 16

2 Answers2

0

The name attribute is used to determine which values are actually posted to the server, so you'll want to ensure that you have one for each value that you are expecting to send :

<select name='GroupID'>
    <!-- Omitted for brevity -->
</select>
<input name='ISBN' />

This would pass the selected option for GroupID to the server and whatever value was stored in your ISBN element. If these two have some type of relationship (as you mentioned you wanted to only use a single <select> element) then you'll likely need to clarify how they are related.

Based on their relationship (if one exists), you could possibly use Javascript to set another hidden ISBN element so that it is posted separately to the server.

Rion Williams
  • 74,820
  • 37
  • 200
  • 327
0

Use of isset(), empty() conditions before using any variable should rectify this.

This error comes up when a variable is unset.

Try this : $ISBN= filter_input($_POST['ISBN'], 'value');

Also refer : Undefined index: id in php

Community
  • 1
  • 1
Ani Menon
  • 27,209
  • 16
  • 105
  • 126