0

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>

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad I could help. Happy coding :)
1

Change

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

to

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.