0

Why my select option got undefined index although in insert theres no error i try to isset and !empty but they got any value on my option can someone enlighten me why i got an error on that part i don`t have problem in my insert code only in update. And tell me why my select option on update modal got undefined while my add or insert dont have error perfectly fine. Undefined index is not posted right?

<form action="categoryedit.php" method="post">
    <div class="row clearfix">
        <div class="form-group">
            <div class="form-line">
                <label>Category No.:</label>
                <input type="text" onkeydown="return alphaOnly(event);" class="form-control" value="<?php echo $categoryno ?>" name="editcategoryno" value="" required autofocus  />
            </div>
        </div>
        <div class="form-group">
            <div class="form-line">
                <label>Category:</label>
                <input type="text" class="form-control" value="<?php echo $genre ?>" name="editgenre" required  />
            </div>
        </div>

        <div class="form-group">
            <div class="form-line">
                <label>Circulation Type:</label>
                <!--     <input type="text" class="form-control" value="<?php echo $section ?>" name="editsection" required  /> -->
                <select name="editsection" class="form-control">
                    <option value="<?php echo $section ?>"><?php echo $section; ?></option>     <option value="<?php if ($section == 'Filipiniana Section') {
                        # code...
                        echo "General Circulation Section";
                    }elseif ($section == 'General Circulation Section') {
                        # code...
                        echo "Filipiniana Section";
                    } ?>"><?php if ($section == 'Filipiniana Section') {
                        # code...
                        echo "General Circulation Section";
                    }elseif ($section == 'General Circulation Section') {
                        # code...

                        echo "Filipiniana Section";
                    } ?></option>
                </select>
            </div>
        </div>



    </div>




</div>

<div class="modal-footer">
    <input type="hidden" name="id" value="<?php echo $id ?>"   />
    <input type="submit" name="submit" class="btn btn-info" value="Submit" />
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>

</div>

</form>

And this is my categoryedit.php

if (isset($_POST['submit'])) {
    $categoryno = mysqli_real_escape_string($connect, $_POST['editcategoryno']);
    $id = mysqli_real_escape_string($connect, $_POST['id']);
    $genre = mysqli_real_escape_string($connect, $_POST['editgenre']);
    $editsection = mysqli_real_escape_string($connect, $_POST['editsection']);
    $searchsql = mysqli_query($connect, "SELECT * FROM category WHERE categoryno = '$categoryno' AND categoryno = '$genre' AND section = '$editsection' ");
    if (mysqli_num_rows($searchsql) == 0) {
        # code...

        $updatequery = mysqli_query($connect, "UPDATE category SET categoryno = '$categoryno', genre = '$genre', section = '$editsection' WHERE id = '$id'");
        if ($updatequery) {
            # code...
            echo "<script>
            alert('Succesfully Update The Category');
            </script>";
        }


    }elseif (mysqli_num_rows($searchsql) != 0) {
        # code...
        echo "<script>
        alert('Already Have This Category No.');
        </script>";
    }

}
Matt
  • 1,518
  • 4
  • 16
  • 30
  • 1
    Possible duplicate of ["Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined) – aynber Mar 12 '19 at 13:28
  • i try to use isset – Alfredo Ramirez Mar 12 '19 at 13:41
  • Show the code with isset, and show your full error message. Just saying "undefined index" does not narrow down where the error is coming from. – aynber Mar 12 '19 at 13:42
  • Notice: Undefined index: editsection in C:\xampp\htdocs\Library\Backend\categoryedit.php on line 14 this is my full error in categoryedit.php i try to use if(isset($_POST['submit']) AND isset($_POST['editsection'])) and not execute code because of the statement – Alfredo Ramirez Mar 12 '19 at 13:47
  • You can also try `!empty($_POST['editsection'])`, but try `var_dump($_POST);` at the top of the `category edit.php` to see what it contains. – aynber Mar 12 '19 at 13:52
  • i also try that !empty try that var_dump – Alfredo Ramirez Mar 12 '19 at 13:54
  • array(4) { ["editcategoryno"]=> string(2) "10" ["editgenre"]=> string(4) "MATH" ["id"]=> string(1) "9" ["submit"]=> string(6) "Submit" } Notice: Undefined index: editsection in C:\xampp\htdocs\Library\Backend\categoryedit.php on line 14 – Alfredo Ramirez Mar 12 '19 at 13:55
  • that show when i submit why no editsection? – Alfredo Ramirez Mar 12 '19 at 13:55
  • So `editsection` is not being passed in. Check the browser source to make sure your select is filled in. You may also want to make it required so that it will always pass in a value. – aynber Mar 12 '19 at 13:57
  • i view my page source this is the code i see – Alfredo Ramirez Mar 12 '19 at 14:03
  • and try to add required on it but still got that error – Alfredo Ramirez Mar 12 '19 at 14:03
  • It looks correct, so I'm at a loss. Watch the Network tab of your developer console to see what it's submitting, and make sure there's no javascript that's modifying your form data. – aynber Mar 12 '19 at 14:07
  • btw how do you see that network tab? yeah it`s correct but all my select option on update got the same error – Alfredo Ramirez Mar 12 '19 at 14:08
  • Bring up the Developer Console in your browser, and there should be a network tab. Make sure to select the option to preserve the log, then click on the request to see data being passed in. – aynber Mar 12 '19 at 14:09
  • i see only categoryedit.php run and no JS that i see or anything – Alfredo Ramirez Mar 12 '19 at 14:16
  • The javascript would be in the page itself, not in the browser console, and something that you might have written. The network tab shows what is being sent to the server. But as I said, I'm at a loss since your code seems to be correct. Sorry. – aynber Mar 12 '19 at 14:19
  • ok thnx btw idk what to do now sad. – Alfredo Ramirez Mar 12 '19 at 14:36

0 Answers0