-1

Line 3

edit_accounts.php

    <?php $get_id = $_GET['id']; ?>
    <?php//  $get_id = isset($_POST['id']) ? $_POST['id'] : ''; ?>

   <div class="container">
    <div class="margin-top">
        <div class="row">   
        <div class="span12">    
    <?php 
    $query=mysqli_query($dbcon,"select * from users_tbl where id ='$get_id'")or die(mysqli_error());
    $row=mysqli_fetch_array($query);
    $id=$row['id'];

    ?>
         <div class="alert alert-info"><i class="icon-pencil"></i>&nbsp;Edit Member</div>
        <p><a class="btn btn-info" href="users.php"><i class="icon-arrow-left icon-large"></i>&nbsp;Back</a></p>
<div class="addstudent">
<div class="details">Please Enter Details Below</div>   
<form class="form-horizontal" method="POST"   action="update_accounts.php" enctype="multipart/form-data">



    <div class="control-group">
        <label class="control-label" for="inputEmail">User_ID:</label>
        <div class="controls">  
        <input type="text" id="inputEmail"  value="<?php echo $row['code'];?>" name="code" >

        </div>
    </div>

    <div class="control-group">
        <label class="control-label" for="inputEmail">Username:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="username"  maxlength="30" value="<?php echo $row['username'];?>"   >

        </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="inputPassword">Firstname:</label>
        <div class="controls">
        <input type="text" id="inputPassword" name="firstname" maxlength="30" value="<?php echo $row['firstname'];?>"  >
        </div>
    </div>

    <div class="control-group">
    <label class="control-label" for="inputPassword">Middlename:</label>
    <div class="controls">
    <input type="text" id="inputPassword" name="middlename" maxlength="30" value="<?php echo $row['middlename'];?>"  >
    </div>
</div>


    <div class="control-group">
        <label class="control-label" for="inputEmail">Lastname:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="lastname" value="<?php echo $row['lastname'];?>" >

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">Email:</label>
        <div class="controls">
        <input type="email" id="inputEmail" name="email" value="<?php echo $row['email'];?>"  >

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">Address:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="address" value="<?php echo $row['address'];?>"   >

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">Contact No:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="contact_number" maxlength="11" value="<?php echo $row['contact_number'];?>">

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">Position:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="position" value="<?php echo $row['position'];?>" >

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">User Type:</label>
        <div class="controls">
        <input type="text" id="inputEmail" name="type_id" value="<?php echo $row['type_id'];?>" >

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">BirthDate:</label>
        <div class="controls">
        <input type="date" id="inputEmail" name="birthdate" value="<?php echo $row['birthdate'];?>">

        </div>
    </div>


<div class="control-group">
        <label class="control-label" for="inputEmail">Date Started:</label>
        <div class="controls">
        <input type="date" id="inputEmail" name="date_started" value="<?php echo $row['date_started'];?>">

        </div>
    </div>


    <div class="control-group">
        <div class="controls">
        <button name="submit" type="submit" class="btn btn-success"><i class="icon-save icon-large"></i>&nbsp;Update</button>
        </div>
    </div>
</form>             

        </div>      
        </div>      
        </div>
    </div>
</div>

     <?php 
     if (isset($_POST['submit'])){
    $usercode=$_POST['code'];
    $username=$_POST['username'];
    $firstname=$_POST['firstname'];
    $middlename=$_POST['middlename'];
    $lastname=$_POST['lastname'];
    $type_id=$_POST['type_id'];
    $birthdate=$_POST['birthdate'];
    $address = $_POST['address'];
    $email=$_POST['email'];
    $password="qwerty";
    $contact_number=$_POST['contact_number'];
    $position=$_POST['position'];
    $date_started=$_POST=['date_started'];

         mysqli_query($dbcon,"UPDATE users_tbl set 
      code='$usercode',firstname='$firstname',lastname='$lastname',middlename = '$middlename',
         lastname = '$lastname',type_id = '$type_id',birthdate = '$birthdate',address = '$address',email = '$email',password = '$password',
      contact_number = '$contact_number',position = '$position',date_started = '$date_started' where id='$id'")or die(mysqli_error());






   ?>  
   <script>alert('Update Status Successful!');
 window.location='accounts.php';</script>;
<?php
}
?>  

accounts.php

       <thead>
                            <tr>
                                <th>User ID:</th>                                    
                                <th>Username</th>                                 
                                <th>Firstname</th>                                 
                                <th>Middlename</th>
                                <th>Lastname</th>                                    
                                <th>Email</th>
                                <th>Address</th>                                 
                                <th>Contact No.</th>                                 
                                <th>Position</th> 
                                <th>User Type:</th>                                    
                                <th>Birthdate:</th>
                                <th>Date Started</th>                                                                
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>

                          <?php $user_query=mysqli_query($dbcon,"select * from users_tbl")or die(mysqli_error());
                            while($row=mysqli_fetch_array($user_query)){
                            $id=$row['id']; ?>
                             <tr class="del<?php echo $id ?>">
                            <td><?php echo $row['code']; ?></td> 
                            <td><?php echo $row['username']; ?></td> 
                            <td><?php echo $row['firstname']; ?></td> 
                            <td><?php echo $row['middlename']; ?></td> 
                            <td><?php echo $row['lastname']; ?></td> 
                            <td><?php echo $row['email']; ?></td> 
                            <td><?php echo $row['address']; ?></td> 
                            <td><?php echo $row['contact_number']; ?></td> 
                            <td><?php echo $row['position']; ?></td> 
                            <td><?php echo $row['type_id']; ?></td> 
                            <td><?php echo $row['birthdate']; ?></td> 
                            <td><?php echo $row['date_started']; ?></td> 
                            <td class="action">                             
                            <a rel="tooltip"  title="Delete" id="<?php echo $id; ?>" href="#delete_book<?php echo $id; ?>" data-toggle="modal"    class="btn btn-danger"><i class="icon-trash icon-large"></i></a>
                            <?php include('delete_book_modal.php'); ?>
                            <a  rel="tooltip"  title="Edit" id="<?php echo $id; ?>" href="edit_accounts.php<?php echo '?id='.$id; ?>" class="btn btn-success"><i class="icon-pencil icon-large"></i></a>


                                </tr>
                                <?php } ?>

                            </tbody>
                        </table>

When I press edit, all information is there and After I click Update the error will show(as you can see in the picture) It's already getting the ID because it will not be show the information if not. And it does not save my update, I change the information but after click the button the information was still the same.

Information

  • Possible duplicate of [PHP: "Notice: Undefined variable", "Notice: Undefined index", and "Notice: Undefined offset"](https://stackoverflow.com/questions/4261133/php-notice-undefined-variable-notice-undefined-index-and-notice-undef) – Rotimi Oct 27 '17 at 04:43
  • 1
    Show the whole "edit_accounts.php" please. E.g. the form submitted through the "Update" button. –  Oct 27 '17 at 04:50
  • Already change it! – rio collins Oct 27 '17 at 04:57
  • Is the form's `action="update_accounts.php"` correct? Then show `update_accounts.php` too. –  Oct 27 '17 at 05:00
  • @aendeerei you did it bro! I actually saw that when you said show the whole edit_accounts, you can add comment that bro! – rio collins Oct 27 '17 at 05:01
  • @aendeerei Ok I will!! Thank you so much!! – rio collins Oct 27 '17 at 05:05
  • @riocollins Perfect then ;-) A tipp: Explain the texts better and add more codes in the future. Good luck. P.S: Sorry, I deleted and readded the comment here. Bye –  Oct 27 '17 at 05:06
  • Only use blockquotes for actual quotes and use bold sparingly for emphasis, not to attract attention, so please remove it. – Funk Forty Niner Oct 30 '17 at 01:23

2 Answers2

0

Try this, Replace :

  $query=mysqli_query($dbcon,"select * from users_tbl where id 
='$get_id'")or die(mysqli_error());

to

  $query=mysqli_query($dbcon,"select * from users_tbl where id 
=$get_id")or die(mysqli_error());

Remove the single quotes. has it is not replacing as its value.

Please let me know if this works for you.

Jason
  • 661
  • 5
  • 17
  • same error " NOTICE: UNDEFINED INDEX: ID IN C:\WAMP64\WWW\DTRNEW\ADMIN\EDIT_ACCOUNTS.PHP ON LINE 3 and adds another error " WARNING: MYSQLI_ERROR() EXPECTS EXACTLY 1 PARAMETER, 0 GIVEN IN C:\WAMP64\WWW\DTRNEW\ADMIN\EDIT_ACCOUNTS.PHP ON LINE 9 " , line 9 is where I erase the '' in the get id – rio collins Oct 27 '17 at 04:48
  • As said by aendeerei, Can you please show me "edit_accounts.php" form – Jason Oct 27 '17 at 04:55
0

you should check, does it return result or no. This error is possible if you do not have proper ID in your DB.

$query=mysqli_query($dbcon,"select * from users_tbl where id ='$get_id'")or die(mysqli_error());
if (!($row=mysqli_fetch_array($query))) {
    echo "Can not find user";
    exit();
}
$id=$row['id'];

PS: spend time to learn what's prepared statements. And do not use way you passed arguments to SQL query. In this case it's very easy to do SQL Injection.

Alex Kapustin
  • 1,869
  • 12
  • 15