猿问

如何在PHP中将这部分代码转换为准备好的语句?

陈述


如何将部分代码转换为准备好的语句?


edit.php


if (isset($_GET['id']))

      {

          $id = $_GET['id'];

          $update = true;

          $sql = "SELECT * FROM crimenews WHERE crimenews_id=$id";

          $query = mysqli_query($conn,$sql);


        if(mysqli_num_rows($query) == 1)

          {

              $row = mysqli_fetch_array($query);

              $category = $row['crimenews_cat'];

              $url = $row['crimenews_url'];

              $datetime = $row['crimenews_datetime'];

              $lat = $row['crimenews_locationLat'];

              $lng = $row['crimenews_locationLong'];

          }

      }

上面的给定链接中已经提供了更多代码。


幕布斯6054654
浏览 143回答 1
1回答

泛舟湖上清波郎朗

// while testing addini_set('display_errors', 1); ini_set('log_errors',1); error_reporting(E_ALL); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);if (isset($_GET['id'])){    $update = true;    $sql = "SELECT * FROM crimenews WHERE crimenews_id=?";    $stmt = $conn->prepare($sql);    $stmt->bind_param('i', $_GET['id']);    $stmt->execute();    $res = $stmt->get_result();    if($res->num_rows == 1)    {        // fetch_assoc() returns just an assoc array and not the numeric array as well        $row = $res->fetch_assoc();        $category = $row['crimenews_cat'];        $url = $row['crimenews_url'];        $datetime = $row['crimenews_datetime'];        $lat = $row['crimenews_locationLat'];        $lng = $row['crimenews_locationLong'];    }}
随时随地看视频慕课网APP
我要回答