gpt4 book ai didi

php - MySQL 数据库更新仅使用数字

转载 作者:行者123 更新时间:2023-11-29 00:37:41 25 4
gpt4 key购买 nike

我的更新表单脚本仅在我使用数字时有效,但如果我尝试使用任何文字,它就无效。我需要帮助,谢谢!

<?php
if(isset($_POST['teams'])){
$home_team = $_POST['home_team'];
$visitor_team = $_POST['visitor_team'];
$sql = mysql_query("UPDATE table1
SET home_team = $home_team, visitor_team = $visitor_team
WHERE active = 1") ;
$retval = mysql_query( $sql, $conn );
if(! $retval ){
die("<p>Error! Could not update team names. Click return button.</p>");
}
echo "<p>Team names set successfully!</p>";
mysql_close($conn);
}
?>

最佳答案

尝试在您的查询中使用 ''

$sql = mysql_query("UPDATE table1 SET 
home_team = '".mysql_real_escape_string($home_team)."',
visitor_team = '".mysql_real_escape_string($visitor_team)."'
WHERE active = '1'") ;

同时添加 mysql_real_escape_string() 来防止 SQL Enjection..

关于php - MySQL 数据库更新仅使用数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13597796/

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