I got this code
我得到了这个代码
<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);
}
?>
and I am using it to insert new values into my database but it is not working, the values are not being added and I dont get any error. Do I have a syntax error?
我正在使用它向数据库中插入新值,但是它不起作用,没有添加值,也没有任何错误。我有语法错误吗?
3 个解决方案
#1
1
You are missing two things:
你漏掉了两件事:
?php
should be <?php
应< ? php ? php
and
和
'".$yearly_income.'")";
should be '".$yearly_income."')";
’”。yearly_income美元。“)”;应该是“yearly_income美元。”)”;
Let me know if that works for you.
如果对你有用,请告诉我。
#2
1
try with:
试一试:
$sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income."')";
Notice the last new position of the last '
注意最后一个新位置'
Also, as @Webeng commented, learn about avoiding MySQL injection in your code. It's very important to have it as a habit.
另外,正如@Webeng所言,了解如何在代码中避免MySQL注入。把它作为一种习惯是很重要的。
#3
0
Why do you check this?
你为什么要检查这个?
if (isset($_POST['submit'])) {
change it to:
把它改成:
if (isset($_POST['yearly_income'])) {
#1
1
You are missing two things:
你漏掉了两件事:
?php
should be <?php
应< ? php ? php
and
和
'".$yearly_income.'")";
should be '".$yearly_income."')";
’”。yearly_income美元。“)”;应该是“yearly_income美元。”)”;
Let me know if that works for you.
如果对你有用,请告诉我。
#2
1
try with:
试一试:
$sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income."')";
Notice the last new position of the last '
注意最后一个新位置'
Also, as @Webeng commented, learn about avoiding MySQL injection in your code. It's very important to have it as a habit.
另外,正如@Webeng所言,了解如何在代码中避免MySQL注入。把它作为一种习惯是很重要的。
#3
0
Why do you check this?
你为什么要检查这个?
if (isset($_POST['submit'])) {
change it to:
把它改成:
if (isset($_POST['yearly_income'])) {