drxyaox153896 2015-08-05 06:40
浏览 7

无法编辑我的php数据[重复]

I have counter an error that cannot view my data after I have update the data into my database.

As my database: Name: item_id; Type: char; Type: Primary key

Error Message:

Notice: Undefined index: item_id in ...\\Testing\itemEdit.php on line 14

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ...\\Testing\itemEdit.php on line 17

Not found Data

This is my itemEdit.php code:

<?php
$host = "localhost";
$username = "root";
$password = "";
$database = "db_test";

// make the connect to mysql
$link = mysql_connect($host, $username, $password);
If ($link == false){
    die ('Could not connect'.mysql_error());
}

//$item_id=$row_item['item_id'];
$itemID = mysql_escape_string($_GET['item_id']);
$strSQL = "SELECT * FROM item_db WHERE item_id = '$itemID'";
$objQuery = mysql_query($strSQL);
while ($objResult = mysql_fetch_array($objQuery)){
if(!$objResult)
{
    echo "Not found Data";
}
else
{
    echo "Error Save [".$strSQL."]";
}
}
mysql_close($link);
?>

<html>
<head>
<title>Staff Edit Record</title>
</head>
<body>
<div style = "border: solid 1px black;
            background-color: beige;">

<p>
    <label for="itemID">&nbsp; Item ID:</label> 
    <input type="text" name="itemID" size="25" value="<?php echo $objResult["item_id"];?>">
</p>

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

Please help to specific and provide the code as I am beginner on php..

Thanks a lot...

</div>
  • 写回答

1条回答 默认 最新

  • doumi2106 2015-08-05 06:47
    关注

    Update your code to following code.

    <?php
    $host = "localhost";
    $username = "root";
    $password = "";
    $database = "db_test";
    
    // make the connect to mysql
    $link = mysql_connect($host, $username, $password);
    if($link == false)
    {
        die ('Could not connect'.mysql_error());
    }
    
    
    $itemID = mysql_escape_string($_GET['item_id']);
    $strSQL = "SELECT * FROM item_db WHERE item_id = '$itemID'";
    $objQuery = mysql_query($strSQL);
    $objResult = mysql_fetch_array($objQuery);
    
    if(isset($_POST))
    {
        //$item_id=$row_item['item_id'];
        $newItemID = mysql_escape_string($_POST['item_id']);
        $strSQL = "UPDATE item_db SET item_id = '$newItemID' WHERE item_id = '$itemID'";
        $objQuery = mysql_query($strSQL);
        while($objResult = mysql_fetch_array($objQuery))
        {
            if(!$objResult)
            {
                echo "Not found Data";
            }
            else
            {
                echo "Error Save [".$strSQL."]";
            }
        }
    }
    mysql_close($link);
    ?>
    
    <html>
    <head>
    <title>Staff Edit Record</title>
    </head>
    <body>
    <div style = "border: solid 1px black; background-color: beige;">
    
    <form method="post" action="">
    <p>
        <label for="itemID">&nbsp; Item ID:</label> 
        <input type="text" name="item_id" size="25" value="<?php echo $objResult["item_id"];?>">
    </p>
    
        <input type="submit" value="UPDATE">
    </form>
    
    
    </div>
    </body>
    </html>
    

    Note mysql extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used.

    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表