我收到了这段代码
<form action="MyCurrentPage.php" method="post" >
<label for="name_of_trainer"> Name Trainer </label>
<input type="text" name="name_of_trainer" id="name_of_trainer"/>
<label for="double"> yearly Income </label>
<input type="text" name="yearly_income id="yearlyincome"/>
<input type= "submit" value="submit" name="submit" />
</form>
?php
if (isset($_POST['submit'])) {
$yearly_income_adition=$_POST['name_of_trainer'];
$yearly_income=$_POST['yearly_income'];
$mysqli->select_db("trainers");
$sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income.'")";
$mysqli->query($sql);
}
?>
我正在使用它将新值插入到我的数据库中,但它不起作用,没有添加值,我也没有收到任何错误。我有语法错误吗?
答案 0 :(得分:1)
尝试:
$sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income."')";
注意上一个'
另外,正如@Webeng评论的那样,了解avoiding MySQL injection in your code。将它作为一种习惯非常重要。
答案 1 :(得分:1)
你遗漏了两件事:
SELECT DATE(FROM_UNIXTIME('fecha unix')) AS fecha,
AVERAGE(Value) AS Average
FROM MyPostsTable
GROUP BY WEEK(FROM_UNIXTIME('fecha unix'))
ORDER BY fecha;
应为?php
和
<?php
应为'".$yearly_income.'")";
请告诉我这是否适合您。
答案 2 :(得分:0)
为什么要检查这个?
if (isset($_POST['submit'])) {
将其更改为:
if (isset($_POST['yearly_income'])) {