douluo5937 2016-09-08 22:51
浏览 15
已采纳

当pin输入php时,显示同一个表中的一行

have this code so someone can check the authenticity of their product buy typing their serial number into a box and it will show if the product come from me and that works perfectly fine but my problem is that I'm trying to echo another Column in the same row that the serial number is in so it will also echo a description of the product once the correct serial number is entered, I've tried a few thing but I'm just going around in circles, any help would great, thanks in advance.

<?php
if(isset($_POST['pin']))
 {
// include Database connection file 
include("db_connection.php");

$pin = mysqli_real_escape_string($con, $_POST['pin']);

$query = "SELECT pin,product FROM auth WHERE pin = '$pin'";


if(!$result = mysqli_query($con, $query))
{
    exit(mysqli_error($con));
}

if(mysqli_fetch_array($result) > 0)
{
    // authentic code entered
    echo '<div style="color: green;"> <b>'.$pin.'</b> This is a genuine product </div>';
}
else
{
    // not valid code entered
    echo '<div style="color: red;"> <b>'.$pin.'</b> Your product is not authentic! </div>';
 }
}
 ?>
  • 写回答

1条回答 默认 最新

  • dpj0015 2016-09-09 00:54
    关注

    Here is how you can get the extra column and show it in your output. Just add the extra column name to your query and output it where you want. Note that I used description for the column name. You might want to rename that to match the real name of the column you want.

    <?php
    if(isset($_POST['pin']))
    {
        // include Database connection file 
        include("db_connection.php");
    
        $pin = mysqli_real_escape_string($con, $_POST['pin']);
    
        $query = "SELECT pin,description FROM auth WHERE pin = '$pin'";
    
    
        if(!$result = mysqli_query($con, $query))
        {
            exit(mysqli_error($con));
        }
    
        if(mysqli_num_rows($result) > 0)
        {
            // authentic code entered
            echo '<div style="color: green;"> <b>'.$pin.'</b> This is a genuine product </div>';
    
            // get extra column and display
            $data = mysqli_fetch_array($result);
            echo '<div>' . $data['description'] . '</div>';
        }
        else
        {
            // not valid code entered
            echo '<div style="color: red;"> <b>'.$pin.'</b> Your product is not authentic! </div>';
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计