0

I'm creating a CRUD application, in which I'm stuck at retrieving the data so that it can be edited further.

Background - This page displays title from the database. After clicking on it, you can see the details related to it which are title, units, category and it also displays a edit button. Now when user clicks on the edit button, a modal is displayed for making changes to that particular title.

`

<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#facultyAddModal">Add Title</button>    
<br><br>
<div class="panel-group" id="facultyAccordion">
    <?php

    for ($i = 0; $i < count($getAll); $i++) {         
        echo <<<HTML
            <div class="panel panel-default">
                <div class="panel-heading"><h4 class="panel-title">
                    <a data-toggle="collapse" data-parent="#facultyAccordion" href="#collapseF{$i}">{$getAll[$i]['title']}</a></h4>
                </div>
                    <div id="collapseF{$i}" class="panel-collapse collapse">
                    <div class="panel-body">
                        <div class="table-responsive">
                            <table class="table table-condensed"><tbody>
                            <tr><td>Title:</td><td>{$getAll[$i]['title']}</td></tr>
                            <tr><td>Units:</td><td>{$getAll[$i]['units']}</td></tr>
                            <tr><td>Category:</td><td>{$getAll[$i]['category']}</td></tr>                             
                            <tbody></table>      
                        </div>
                        <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#titleEditModal" onclick="titleEditModal('{$getAll[$i]['titleId']}')><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Edit Title</button>

 </div>
              </div>  
            </div>
 HTML;
    }
    ?>
    </div>

<!-- Title Edit Modal --> 
<div class="modal fade" id="titleEditModal" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Edit Title</h4>
        </div>
        <div class="modal-body">
            <!-- Title edit Modal Fail Alert-->
            <div id="adminResult" class="hide" role="alert">
           <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
             <div id="resultAdminContent"></div>
            </div>
            <!-- editTitle Form-->
            <form id="editTitle" method="post">
                <div class="form-group">
                    <label for="desc">Title:</label>
                    <input type="text" class="form-control" id="editadminTitle" name="title" value=""<?php echo $getdata['title'];?>"">
                </div>
                <div class="form-group">
                    <label for="desc">Units:</label>
                    <input type="text" class="form-control" id="editadminUnits" name="units" value=""<?php echo $getdata['units'];?>"">
                </div>
                <div class="form-group">
                    <label for="year">Category:</label>
                    <input type="text" class="form-control" id="editadminCategory" name="category" value="<?php echo $getdata['category'];?>" >
                </div>

                <input type="hidden" class="form-control" id="editadminTypeId" value=''>
                <br>
                <button type="submit" class="btn btn-default">Submit</button>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
    </div>
</div>

`

I want the data to be displayed in the modal for the user to make changes to it. But I'm getting error in each of the field which says - '
Notice: Undefined index: category in C:\Apache24\htdocs\PhpProject1\admin.php on line 103
'

AAM
  • 321
  • 5
  • 24
  • Please add `var_dump` of `$getAll` - seem like he missing the category key... – dWinder May 16 '19 at 17:47
  • The notice is pretty clear, there is nothing called "category" in your resultset. Check your sql or database. My bet is that your SQL query is referencing it as "catagory" or your database column is "catagory", or your query does not include "category" in the resultset. – Jacob S May 16 '19 at 17:49
  • Hey, adding var_dump didn't work.. also, category is the field's name. Getting similar error for title and units too. i.e Undefined index: title in C:\Apache24\htdocs\PhpProject1\admin.php on line 103 ' – AAM May 16 '19 at 17:49
  • It's just the edit modal which isn't displaying the data in the input fields. Otherswise the same data is displayed on the same page. – AAM May 16 '19 at 17:51
  • 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) – snwflk May 16 '19 at 18:35

0 Answers0