php mysql 里面有字母找不到id

php mysql cant find id if there is letters inside

当我尝试用数字搜索可用的 ID 时,它正确回显。

但是,如果里面只有一个字母,比如:5325252T,它不会在数据库中找到它。 我有一列类型:longtext

我该如何解决这个问题?以前没注意到这个问题,现在急着修复...

顺便说一句,如果我回显 rusp_9_cf7dbplugin_submits 的所有表格,它还会显示那些里面有字母的 ID。真的很奇怪。

    // Create connection
$conn = new mysqli($hostname, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT field_value FROM rusp_9_cf7dbplugin_submits WHERE field_value = 5325252T"; // If i remove the T, It will find the id and echo it in a table, but if the T is there, it wont find the id at all...
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    echo "<table><tr><th>ID</th><th>Name</th></tr>";
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<tr><td>".$row["field_value"]."</td><td>".$row["field_value"]." ".$row["field_value"]."</td></tr>";
    }
    echo "</table>";
} else {
    echo "0 results";
}
$conn->close();

只需将 field_value 值括在单个引号 ' 中,因为添加一个字符会使 SQL 引擎将该值解释为数字,因为它是 string literal,而如果它只是数字,那么它会将其解释为 integer.

您的代码变为...

...
$sql = "SELECT field_value FROM rusp_9_cf7dbplugin_submits WHERE field_value = '5325252T'"; // If i remove the T, It will find the id and echo it in a table, but if the T is there, it wont find the id at all...
...