dpaal28266 2018-07-07 03:45
浏览 52
已采纳

PHP Sql导入无法正常工作[重复]

This question already has an answer here:

Im trying to insert data into my database, it works when i dont use the $_POST['wagee'], but I cant get it to work pulling data from my form. Any help is greatly appreciated. Thank you!

here is the error I get:

You have an error in your SQL syntax; check the manual that corresponds
to your MySQL server version for the right syntax to use near ' '2')' 
at line 2

This is my code:

<?php 

$message = ""; 

if(isset($_POST['addhoursbutton']))
{
   addwage();
} 

function addwage() {
include 'components/sql/config.php';

$sqlupdateincome = "INSERT INTO income (username, projectname, hourlywage, totalhours)
VALUES ('John', 'Ochrom Test', ". $_POST['wagee'] .", '2')";

if ($conn->query($sqlupdateincome) === TRUE) {
    echo "New record created successfully";
} else {
     echo  "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • dqhdpppm02183 2018-07-07 03:54
    关注

    I think you missed the quotes around the value.

    It should be '". $_POST['wagee'] ."'

    $sqlupdateincome = "INSERT INTO income (username, projectname, hourlywage, totalhours)
    VALUES ('John', 'Ochrom Test', '". $_POST['wagee'] ."', '2')";
    

    It's not recommended to use user inputs directly in your queries though. I hope this is only for learning purposes.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效