获取显示在文本字段中的值

时间:2016-03-13 18:53:28

标签: php

我正在尝试从按下EDIT按钮后的数据库中获取值以显示在文本字段中。但是我收到了这个错误

  

注意:尝试获取非对象的属性   第47行的C:\ xampp \ htdocs \ demo \ edit.php

我能以正确的方式获得价值吗?我该如何解决这个问题?谢谢你的进步

的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);
?>

主要代码

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>

0 个答案:

没有答案