我们正在使用 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Ü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
此外,您在同一代码中使用了 mysqli
和 mysql
。
如果您开始使用 mysqli
连接到您的数据库,您必须使用它进行查询。
mysqli_query($db, $variable);
关于php - 用颜色值填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27011786/