php - 用颜色值填充数据库

标签 php mysql html apache xampp

我们正在使用 Xampp 来模拟 apache 和 mysql 服务器。 我不知道到底是什么问题。当我检查数据库时,它没有任何值(value)。

数据库:http://de.tinypic.com/r/53285/8

这是我的 html 代码:

<!DOCTYPE html>
<html>
<body>
<form action="data.php" method="POST">
<input type="radio" name="Color" value="b" id="r"/>
<label for="radio">ROT</label></br>
<input type="radio" name="Color" value="b" id="g"/>
<label for="radio">GR&Uuml;N</label></br>
<input type="radio" name="Color" value="b" id="b"/>
<label for="radio">BLAU</label></br>
<button type="submit">Absenden</button>
</form>
</body>
</html>

这是我的 php 代码:

<?php

$db = mysqli_connect("localhost", "root", "", "lightcontrol");
if(!$db)
{
exit("Verbindungsfehler: ".mysqli_connect_error());
}

if(isset($_POST["Color"]))
{

if($_POST["Color"]=="r")
{
$variable =" INSERT INTO valuetb VALUES(`1`,,`255`,`0`,`0`)";
}
if($_POST["Color"]=="g")
{
$variable =" INSERT INTO valuetb VALUES(`1`,,`0`,`255`,`0`)";
}
if($_POST["Color"]=="b")
{
$variable =" INSERT INTO valuetb VALUES(`1`,,`0`,`0`,`255`)";
}
}
var_dump($variable);
mysqli_query($db,$variable);

?>

最佳答案

正如其他人所指出的,您的查询是错误的。 Check documentation查看必须如何完成 INSERT

此外,您在同一代码中使用了 mysqlimysql。 如果您开始使用 mysqli 连接到您的数据库,您必须使用它进行查询。

mysqli_query($db, $variable);

关于php - 用颜色值填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011786/

相关文章:

php - 发生数据库错误错误号-1054

php - PHP错误-语法错误,意外 'extends'(T_EXTENDS)

c# - 必须关闭 MySqlDataReader

html - 是否有可能有一个 :after pseudo element on a button?

JavaScript 双下拉菜单

php - 好友关注/取消关注表结构#MySQL

php - SQL WeekOfYear() 在年底停止。备择方案?

mysql - varchar 数据类型不接受数据转储中的字符

mysql - mantis 新用户注册无需邮箱

javascript - 运行单击并双击 anchor 标记