MySQL表插入 [英] MySQL table insertion
本文介绍了MySQL表插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道我的表写入是否正确,它似乎失败了.
I'd like to know if I am doing a correct table write, it seems to be failing.
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();
请注意,最后一部分被严重屠杀,这正是我需要帮助的地方.
Be aware that last part is badly butchered, and is what I need help with.
推荐答案
您的插入语句中似乎缺少字符串分隔符.
You seem to be missing string delimiters in your insert statement.
即
$temp = mysql_query("INSERT INTO streamer_ids (username,streamer_id,premium) VALUES('".$username."','".$randstring."','0')");代码>
此外,我不知道 $username 值的来源,但您可能应该对其进行清理以防止 SQL 注入.IE.在其上运行 addslashes
.
Also, I don't know where the $username value is coming from, but you should probably sanitize it in order to prevent SQL injections. I.e. Running addslashes
on it.
- 基督徒
这篇关于MySQL表插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文