简体   繁体   English

MySQL表插入

[英]MySQL table insertion

Is this accepted syntax? 这是可接受的语法吗? More importantly, will it work? 更重要的是,它将起作用吗?

$temp = mysql_query("INSERT INTO streamer_ids (username,streamer_id,premium) VALUES($username,$randstring,0)");
    $temp->closeCursor();

You need to put quotes around the strings to make it work. 您需要在字符串两边加上引号以使其起作用。

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

Sp. Sp。 if you are connected to MySQL, then it will work WITH these changes. 如果您连接到MySQL,则可以使用这些更改。 Also, don't forget to take preventive measures against SQL injection attacks. 另外,不要忘记对SQL注入攻击采取预防措施。 For that, you should do this to all the variables before running the query: 为此,您应该在运行查询之前对所有变量执行此操作:

$username = mysql_real_escape_string($username);
$randstring = mysql_real_escape_string($randstring);
$premium = intval($premium); //supposing it is always integer.
$tempquery = "INSERT INTO streamer_ids (username,streamer_id,premium) VALUES($username,$randstring,0);
$result = mysql_query($tempquery);

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM