gpt4 book ai didi

php - 检查表(phpmyadmin、php、mysql)中的值,仅返回 0

转载 作者:行者123 更新时间:2023-11-29 11:47:36 28 4
gpt4 key购买 nike

我正在尝试创建一个页面来查找您输入的文本是否存在于我的数据库表中。但即使存在,它也只返回 0。

<?php
$db = mysql_connect("database", "user", "password") or die("Could not connect to MySQL. ".MySQL_error());
mysql_select_db("myData",$db);
?>
<form method = "POST" action = "website.php">
<input type = "text" name = "text">
<input type = "submit" name = "button1" value = "check">
</form>
<?php
if(isset($_POST["button1"])) {
$txt = $_POST['text'];
$sql = mysql_query("SELECT COUNT(*) as total FROM myText WHERE text = $txt");
$quantity = mysql_fetch_assoc($sql);
echo $quantity['total'];
}
?>

最佳答案

<?php
$db = mysqli_connect("host", "user", "password", "database");
?>
<form method = "POST" action = "website.php">
<input type = "text" name = "text">
<input type = "submit" name = "button1" value = "check">
</form>
<?php
if(isset($_POST["button1"])) {
$txt = $_POST['text'];
$sql = mysqli_query($db, "SELECT COUNT(*) as total FROM myText WHERE text = '".$txt."'");
$quantity = mysqli_fetch_object($sql);
echo $quantity->total;
}
?>

关于php - 检查表(phpmyadmin、php、mysql)中的值,仅返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34653580/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com