doufuhuang6981 2015-10-29 16:34
浏览 34

如何将值插入MYSQL

I'm trying to add value to database when each voter will vote with his ID. My db get the value but it goes one row down and i want that the db to get the value 1 to ID row not one row down.

Any solution about this please!!!

This is my code

$before1    = $row['vote_one_before'];
$after1     = $row['vote_one_after'];
$before2    = $row['vote_two_before'];
$after2     = $row['vote_two_before'];
$before3    = $row['vote_three_before'];
$after3     = $row['vote_three_after'];

$vote = 1;

if(($before1 == 0) and ($after1 == 0) and ($before2 == 0) and ($after2 == 0) and ($before3 == 0) and ($after3 == 0)){
    $stmt = $conn->prepare("INSERT INTO DB (vote_one_before) VALUES(':vote_one_before')");
    $stmt->execute(array(':vote_one_before'=> $vote));
}

enter image description here

  • 写回答

1条回答 默认 最新

  • donglang7236 2015-10-29 16:40
    关注

    Issue 1: If/Else

    AND is not an operator that can be used in an IF/ELSE function - you need &&. Change your IF line to:

    if(($before1 == 0)&&($after1 == 0)&&($before2 == 0)&&($after2 == 0)&&($before3 == 0)&&($after3 == 0)){
    

    Issue 2: Query

    Your query is also incorrect. For INSERT, the format is:

    INSERT INTO `table_name` (`column_name`) VALUES (`new_value`);
    

    Unless "DB" is your table name, you'll need to amend your query to something like this:

        $stmt = $conn->prepare("INSERT INTO `table_name` (vote_one_before) VALUES (:vote_one_before)");
    

    Also note that when using placeholders you don't need single or double quotes - so ':vote_one_before' becomes :vote_one_before.

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭