php - MySQL表插入

标签 php mysql

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

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/

相关文章:

mysql - 仅在 MYSQL DATEDIFF 中显示小时数

mysql - MySQL数据库数据迁移到SQL Server

php - Laravel ID 不匹配

php - 使用 ajax 自动更新 .txt

php - 使用 PHP 预选 MySQL 填充的下拉列表

php - Magento:修改时事通讯模块

mysql - Redis 独立服务器或与 MySQL 一起使用

c# - 通过 C# 将 JSON 数据 POST 到 PHP 并将值存储在 MYSQL 中

php - 如何使用正则表达式在 PHP 中将字符串设为 "clean"?

MySQL 日期、分钟 添加值