不起作用。我正在尝试如下。

if (($row["steamid"]) == $steamprofile['steamid']){


以下是完整的代码段。

<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$eh = $steamprofile[steamid];
$sql = "SELECT steamid FROM Main";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        if (($row["steamid"]) == $steamprofile['steamid']){
echo "SteamID Is Equal and Created!";
}

    }
} else {
    echo "Nope?";
}

$conn->close();
?>


香港专业教育学院尝试了各种方法。

最佳答案

// Create connection
$conn = new mysqli("localhost", "root", "", "stackoverflow");
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
//assume 1
$steamprofile['steamid']=1;

// changes here single quote
$eh = $steamprofile['steamid'];

$sql = "SELECT steamid FROM Main";

$result = $conn->query($sql);
if ($result->num_rows > 0)
{
    // output data of each row
    while($row = $result->fetch_assoc())
{
        if (($row["steamid"]) == $steamprofile['steamid']){
echo "SteamID Is Equal and Created!";
}

    }
} else {
    echo "Nope?";
}

$conn->close();
?>


输出是
SteamID相等且已创建!

MySQL数据库------------
如果不存在则创建表main
steamid int(11)非空,
  name varchar(500)非空
)ENGINE = InnoDB AUTO_INCREMENT = 3 DEFAULT CHARSET = latin1;

-

-转储表main的数据

插入mainsteamidname)值
(1,'test1'),
(2,'test2');

关于php - 如果SteamID等于MYSQL行,则为PHP,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34796171/

10-12 18:33