Home > Blockchain >  No display after getting all Id's using checkbox
No display after getting all Id's using checkbox

Time:10-17

Hello guys can you please help me to solve this. This happen suddenly last few days. no display after getting all the id from my index to edit form.

index file:

<?php 
include('header.php');
?>
<body>
<div class="container">
<br>
<br>
<form action="edit.php" method="post">
    <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
        <div class="alert alert-success">
            <h2 style="text-align:center; font-family:cursive;">Edit Multiple Rows in PHP/MySQL with Checkbox</h2>
        </div>
        <thead>
            <tr>
                <th style="text-align:center; font-size:18px; color:blue;">FirstName</th>
                <th style="text-align:center; font-size:18px; color:blue;">LastName</th>
                <th style="text-align:center; font-size:18px; color:blue;">MiddleName</th>
                <th style="text-align:center; font-size:18px; color:blue;">Address</th>
                <th style="text-align:center; font-size:18px; color:blue;">Email</th>
                <th style="text-align:center; font-size:18px; color:blue;">Action</th>
            </tr>
        </thead>
        <tbody>
        <?php
        $conn = new mysqli("localhost", "root", "123456", "multi_edit") or die(mysqli_error());
        $query = $conn->query("SELECT * FROM `member`") or die(mysqli_error());
        while($row = $query->fetch_array()){
            
        ?>
        <?php 
         ?>
            <tr>
                <td style="text-align:center; font-size:18px;"><?php echo $row['firstname'] ?></td>
                <td style="text-align:center; font-size:18px;"><?php echo $row['lastname'] ?></td>
                <td style="text-align:center; font-size:18px;"><?php echo $row['middlename'] ?></td>
                <td style="text-align:center; font-size:18px;"><?php echo $row['address'] ?></td>
                <td style="text-align:center; font-size:18px;"><?php echo $row['email'] ?></td>
                <td style="text-align:center; font-size:18px;">
                    <input name="selector[]" type="checkbox" value="<?php echo $id; ?>">
                </td>
            </tr>
        <?php  } ?>                      
        </tbody>
    </table>
    <br />              
    <button class="btn btn-success pull-right" style="font-family:cursive;" name="submit_mult" type="submit">
        Update Data
    </button>
</form>



</div>
</body>
</html>

edit file:

<?php 
include('header.php');
?>
<body>
<br />

<div class="container">

<a href="index.php" style="margin-left: 165px; " class="btn btn-danger">Return</a>
<br />
<br />
<form class="form-horizontal" action="edit_save.php" method="post">    
<?php

$id=$_POST['selector'];
$N = count($id);
for($i=0; $i < $N; $i  )
{
    $conn = new mysqli("localhost", "root", "123456", "multi_edit") or die(mysqli_error());
    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
    $query = $conn->query("SELECT * FROM `member` where member_id='$id[$i]'") or die(mysqli_error());
    while($row = $query->fetch_array())
// $result = mysql_query("SELECT * FROM member where member_id='$id[$i]'");
// while($row = mysql_fetch_array($result))
{ ?>
    <div class="thumbnail" style="margin:auto; width:600px;">
    <div style="margin-left: 70px; margin-top: 20px;">
        <div class="control-group">
        <label class="control-label" for="inputEmail" style="font-family:cursive; font-weight:bold; font-size:18px; color:blue;">Firstname</label>
        <div class="controls">
        <input name="member_id[]" type="hidden" value="<?php echo  $row['member_id'] ?>" />
            <input name="firstname[]" type="text" style="font-family:cursive; font-weight:bold;" value="<?php echo $row['firstname'] ?>" />
        </div>
        </div>
        
        <div class="control-group">
        <label class="control-label" for="inputEmail" style="font-family:cursive; font-weight:bold; font-size:18px; color:blue;">Lastname</label>
        <div class="controls">
            <input name="lastname[]" type="text" style="font-family:cursive; font-weight:bold;" value="<?php echo $row['lastname'] ?>" />
        </div>
        </div>
    
        <div class="control-group">
        <label class="control-label" for="inputEmail" style="font-family:cursive; font-weight:bold; font-size:18px; color:blue;">Middlename</label>
        <div class="controls">
            <input name="middlename[]" type="text" style="font-family:cursive; font-weight:bold;" value="<?php echo $row['middlename'] ?>" />
        </div>
        </div>
        
        <div class="control-group">
        <label class="control-label" for="inputEmail" style="font-family:cursive; font-weight:bold; font-size:18px; color:blue;">Address</label>
        <div class="controls">
            <input name="address[]" type="text" style="font-family:cursive; font-weight:bold;" value="<?php echo $row['address'] ?>" />
        </div>
        </div>
        
        <div class="control-group">
        <label class="control-label" for="inputEmail" style="font-family:cursive; font-weight:bold; font-size:18px; color:blue;">Email Address</label>
        <div class="controls">
            <input name="email[]" type="text" style="font-family:cursive; font-weight:bold;" value="<?php echo $row['email'] ?>" />
        </div>
        </div>
    </div>
    </div>

    <br />  
<?php 
}
}
?>
<input name="" class="btn btn-success" style="margin-left: 165px; font-family:cursive;" type="submit" value="Update">
</form>

</div>
</body>
</html>

My index form

My edit form

Please I cant track wheress the problem, last few days this code works perfectly fined. I tried clearing my browser data and I tried also edit my code but still no display. Thank you guys.

CodePudding user response:

Are you sure you did not change something and it used to work like that ?

 <td style="text-align:center; font-size:18px;"><?php echo $row['firstname'] ?></td>

$row['firstname'] is outside your query, where do you get the $row from? Also after echo you need a ; for exapmle echo $row['firstname'] ;

CodePudding user response:

I already fixed the error guys. this <input name="selector[]" type="checkbox" value="<?php echo $id; ?>"> I changed to <input name="selector[]" type="checkbox" value="<?php echo $row['member_id']; ?>"> Im so relived. I think my partner on this system changed this so that I didn't see immediately. Thank you so much!

  •  Tags:  
  • php
  • Related