0

I am trying the get the value from database to display in the text field after pressed EDIT button. But I got this error

Notice: Trying to get property of non-object in C:\xampp\htdocs\demo\edit.php on line 47

Am I getting the value in the right way? How can I fix this issue? Thanks in advances

config.php

<?php
$currency = '$'; //Currency sumbol or code

$db_username = 'root';
$db_password = '';
$db_name = 'demo';
$db_host = 'localhost';
$mysqli = new mysqli($db_host, $db_username, $db_password,$db_name);
?>

main code

include('config.php');
$status = "";
$id = (isset($_POST['id']) ? $_POST['id'] : null);

$my_query = $mysqli->query("SELECT * from items where id='".$id."'"); 
// $result = mysql_query($query) or die ( mysql_error());

$obj=$my_query->fetch_object();

    if(isset($_POST['new']) && $_POST['new']==1) {
        $id                 = $_REQUEST['id'];
        $product_code       = $_REQUEST['product_code'];
        $product_name       = $_REQUEST['product_name'];
        $product_desc       = $_REQUEST['product_desc'];
        $product_img_name   = $_REQUEST['product_img_name'];
        $price              = $_REQUEST['price'];
        $price_big          = $_REQUEST['price_big'];
        $product_type       = $_REQUEST['product_type'];

        $edit_query = $mysqli->query("UPDATE items SET id='$id.', product_code='$product_code', product_name='$product_name', 
            product_desc='$product_desc', product_img_name='$product_img_name', price='$price', price_big='$price_big', product_type='$product_type' WHERE id='$id'");

        $status = "Updated Successfully.</br></br><a href='admin.php?appetizers_Soup'>View Updated Record</a>";
        // echo '<p style="color:#FF0000;">'.$status.'</p>';
    }

    <form name="form" method="post" action="">
        <input type="hidden" name="new" value="1" />
        <input name="id" type="hidden" value="<?php echo $obj->id;?>" />
        <p><input type="text" name="id" placeholder="Enter ID" value="<?php echo $obj->id; ?>"  required /></p> //Error is here
        <p><input type="text" name="product_code" placeholder="Enter Product Code" required /></p>
        <p><input type="text" name="product_name" placeholder="Enter Product Name" required /></p>
        <p><input type="text" name="product_desc" placeholder="Enter Product Description" required /></p>
        <p><input type="text" name="product_img_name" placeholder="Enter Product Image" /></p>
        <p><input type="text" name="price" placeholder="Enter Price 1" required /></p>
        <p><input type="text" name="price_big" placeholder="Enter Price 2" /></p>
        <p><input type="text" name="product_type" placeholder="Enter Product Type" /></p>
        <p><input name="submit" type="submit" value="Submit" /></p>
    </form>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Rick Ng
  • 69
  • 1
  • 1
  • 10

0 Answers0