0

首先,对不起英语不好:(
我想要像steam,origin或uplay这样的密钥系统。我给用户密钥,用户将该代码写入输入,代码将回显用户的代码。

我有1个表。2列。2 2 列的行。像这样:

.----------------------.
|  sifre  |  bizimkey  |
|______________________|
|  A5Sr2A | First Code |
|______________________|
|  FaQ1fS | Scnd. Code |
|______________________|

如果用户在 Input 中输入 A5Sr2A,PHP 会回显“First Code”。如果用户输入错误的代码,就会出现警报。

我尝试了很多代码。我可以像这样运行代码:

<?php
 if ($_POST['pass'] == "A5Sr2A") {
     {
         echo "First Code";
     }
 } else {
     header('Location:index.html');
 }
?>

但我不想要这个。这是非常具有挑战性的事情。我问自己,“你为什么不使用 MySQL?”
我正在尝试 7 小时。真的。我想这样做。我想学习MySQL。请帮忙。谢谢!

    <? ob_start(); ?>
    <html>
        <link rel=stylesheet href="style.css">
        <table>
            <tr>
                <td>
                    <center>
<?php 
$host = "localhost";
$user = "user";
$password = "pass";
$database = "db";
$con = mysqli_connect($host, $user, $password, $database);
if (mysqli_connect_errno()) {
    echo "ERROR";
}
$result = m ysqli_query($con, "SELECT sifre FROM keyler");
if ($_POST['pass'] == $ result) {
    {
        $mykey = m ysqli_query($con, "SELECT bizimkey FROM keyler");
        echo $mykey;
    }
} else {
    header('Location:index.html');
}
mysqli_close($con);
?>
                    </center>
                </td>
            </tr>
        </table>

    </html>
    <? ob_flush(); ?>
4

1 回答 1

0

好的,请参见下面的基本实现示例:

$host = "localhost";
$user = "user";
$password = "pass";
$database = "db";
$con=mysqli_connect($host,$user,$password,$database);
if(mysqli_connect_errno()!=0)//mysqli_connect_errno() returns 0 when there are no errors
{
    echo "ERROR";
}
$sifre_test = mysqli_real_escape_string($con,$_POST['pass']);
$result = mysqli_query($con,"SELECT '1' FROM `keyler` WHERE `sifre`='".$sifre_test."'");
if($result!==false)
{
    //If $result !== false, the query was successful, so we'll try to grab a row
    $row = mysqli_fetch_assoc($result);
    //$row will be null if there wasn't a row found where `sifre`=$sifre_test
    if(!is_null($row))
    {
        $result = mysqli_query($con,"SELECT `bizimkey` FROM `keyler` WHERE `sifre`='".$sifre_test."'");
        if($result!==false)
        {
            $row = mysqli_fetch_assoc($result);
            $bizimkey = $row['bizimkey'];
            echo $bizimkey;
        }
        else
        {
            die("bizimkey query failed");
        }
    }
}
else
{
    die("sifre query failed");
}

为了更好地理解和更多示例,请参阅以下文档链接:

mysqli_query mysqli_fetch_assoc

于 2013-08-25T22:05:03.353 回答