首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用isset来修正?

用isset来修正?
EN

Stack Overflow用户
提问于 2014-05-22 06:23:17
回答 2查看 51关注 0票数 0

我刚开始使用PHP,我的网页出现了错误,page.It说:

注意:未定义的索引:第103行中的/home/tz005/public_html/home 1687/ed.php中的itemid

我能用isset来解决这个问题吗?如果是,如何做到?这是我的剧本:

代码语言:javascript
复制
<?php
//include database connection
include 'dbconnect.php';

// if the form was submitted/posted, update the item
if($_POST){

    //write query
    $sql = "UPDATE 
                item_information 
            SET
                itemtitle = ?, 
                itemdescription = ?,
                date = ?,
            WHERE 
                itemid= ?";

    $stmt = $mysqli->prepare($sql);

    $stmt->bind_param(
        'sssi', 
        $_POST['itemtitle'], 
        $_POST['itemdescription'],
        $_POST['date'],
        $_POST['itemid']
    );

    // execute the update statement
    if($stmt->execute()){
        echo "Item was updated.";

        // close the prepared statement
        $stmt->close();
    }else{
        die("Unable to update.");
    }
}

$sql = "SELECT 
            itemid, itemtitle, itemdescription, date
        FROM 
            item_information
        WHERE 
            id = \"" . $mysqli->real_escape_string($_GET['itemid']) . "\"
        LIMIT 
            0,1";

// execute the sql query
$result = $mysqli->query( $sql );

//get the result
if ($result = $mysqli->query( $sql )) {
  if ($row = $result->fetch_assoc()) {

    // $row contains data

  }
}

//disconnect from database
$result->free();
$mysqli->close();
?>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-05-22 06:27:05

变化

代码语言:javascript
复制
$mysqli->real_escape_string($_GET['itemid'])

代码语言:javascript
复制
$mysqli->real_escape_string($_POST['itemid'])

或者使用empty()isset()检查存在的值。

票数 1
EN

Stack Overflow用户

发布于 2014-05-22 06:27:56

是的,您可以使用isset()函数来完成

为它创造条件

代码语言:javascript
复制
if(isset($_GET['itemid'])){
  //execute your code
}
else{
 //header them back to page or show error that itemid not set or something else whatever suits you
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23799223

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档