简体   繁体   中英

Need help in editing a data in mysql using php

I've already searching about my problem for 2 days, but nothings happen. I need your help to fix my problem in editing a data using mysql and php

prod_list.php

<?php
  $result = mysql_query("SELECT * FROM product ORDER BY prod_id DESC");
  while($row = mysql_fetch_array($result)) { 
  $image = $row['7']; 
?>
  <tr>
  <td><?php echo $row["0"]; ?></td>
  <td><?php echo $row["1"]; ?></td>
  <td><?php echo $row["2"]; ?></td>
  <td><?php echo $row["3"]; ?></td>
  <td><?php echo $row["4"]; ?></td>
  <td><?php echo $row["5"]; ?></td>
  <td><?php echo $row["6"]; ?></td>
  <td> <img src="\sns/uploads/<?php echo $image; ?>" width="30" height="25"></td>
  <td><?php echo $row["8"]; ?></td>
  <td><?php echo "<a href='index.php?page=9adnk3b8nc&prodid={$row['0']}' class='btn btn-info btn-fill btn-sm pull-right'>Edit</a>"; ?></td>
 </tr>
 <?php  } ?>

When I click the edit. nothing shows up. this is my edit form ..i tried some other edit codes but all of these comes up an error : Undefined variable "prod_id" .

edit_product.php

<div class="content">
<?
$prod_id=$_GET["prod_id"];
$query="select * from product where prod_id='$prod_id'";
$result=mysql_query($query);
while ($row = mysql_fetch_array($result)) {
?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
    <?php

        if(isset($_POST['submit']))
        {

        }
    ?>
    </div>
    <div class="col-md-8">
            <div class="form-group">
                <label>Product ID</label>
                <input type="hidden" class="form-control" name="id" autocomplete="off" placeholder="Product Name" value="<?php echo $row['prod_id']; ?>">
            </div>        
    </div>

Its because of variable mismatch.

The Edit link has parameter prodid and in edit_product.php it is $_GET["prod_id"]

Change $_GET["prod_id"] to $_GET["prodid"] and it should work.

Change

index.php?page=9adnk3b8nc&prodid={$row['0']}'

to

index.php?page=9adnk3b8nc&prod_id={$row['0']}'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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