gpt4 book ai didi

php - MySQL表插入

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

我想知道我是否在进行正确的表写入,它似乎失败了。

while($n != 1)
{
$randstring = "live_".RandomString();
echo "<br>".$username."<br>";
echo $randstring."<br>";
$idcheck = mysql_query("SELECT * FROM streamer_ids WHERE streamer_id='".$randstring."'"); //check for matching random strings
if (!(mysql_num_rows($idcheck)>0))
{
$n=1; //It has found a random string that does not match.
}
}
//if it has reached this far, it has a unique id. Now that id is being written to the database.
$temp = mysql_query("INSERT INTO streamer_ids (username,streamer_id,premium) VALUES(".$username.",".$randstring.","0")");
$temp->closeCursor();

请注意,最后一部分被严重屠宰,这正是我需要帮助的地方。

最佳答案

您的插入语句中似乎缺少字符串定界符。

$temp = mysql_query("INSERT INTO streamer_ids (username,streamer_id,premium) VALUES('".$username."','".$randstring."','0')");

此外,我不知道 $username 值的来源,但您可能应该对其进行清理以防止 SQL 注入(inject)。 IE。在其上运行 addslashes

  • 基督教

关于php - MySQL表插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4394723/

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