简体   繁体   English

传递未定义的索引 ID

[英]Passed Undefined Index ID

Line 3 3号线

edit_accounts.php 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帐户.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.当我按编辑时,所有信息都在那里,在我点击更新后,错误将显示(如图所示)它已经获得了 ID,因为如果没有,它将不会显示信息。 And it does not save my update, I change the information but after click the button the information was still the same.它不保存我的更新,我更改了信息,但单击按钮后信息仍然相同。

Information信息

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.请让我知道这是否适合您。

you should check, does it return result or no.你应该检查一下,它是否返回结果或没有。 This error is possible if you do not have proper ID in your DB.如果您的数据库中没有正确的 ID,则可能会出现此错误。

$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. PS:花时间学习一下准备好的语句。 And do not use way you passed arguments to SQL query.并且不要使用您将参数传递给 SQL 查询的方式。 In this case it's very easy to do SQL Injection.在这种情况下,很容易进行 SQL 注入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM