doujia2463 2012-10-28 02:21
浏览 64
已采纳

MySQL查询不插入数据

I'm in a bit of a pickle here, its just that I'm trying to enter some data that I get from users into a table, but for some reason it won't let me insert the data, however I have exactly the same query for another part of the table and that seems to work perfectly fine.

for example when I execute this query, it doesn't work:

$updateibtask2 = "UPDATE ibtask_task2_75beep SET 

    Trial1_tone_actual=  '$taskerror[0]', Trial2_tone_actual= '$taskerror[1]',  Trial3_tone_actual= '$taskerror[3]',

    Trial4_tone_actual=  '$taskerror[4]', Trial5_tone_actual= '$taskerror[5]',  Trial6_tone_actual= '$taskerror[6]', 

    Trial7_tone_actual=  '$taskerror[7]', ... WHERE user_id = '$memberid'";

However, when I try this query it works perfectly fine:

$updateibtask2_estimate = "UPDATE ibtask_task2_75beep SET 

    Trial1_tone_estimate=  '$taskerror[0]', Trial2_tone_estimate= '$taskerror[1]',  Trial3_tone_estimate= '$taskerror[3]',

    Trial4_tone_estimate=  '$taskerror[4]', Trial5_tone_estimate= '$taskerror[5]',  Trial6_tone_estimate= '$taskerror[6]', 

    Trial7_tone_estimate=  '$taskerror[7]', ... WHERE user_id = '$memberid'";

I'm just wondering where I'm going wrong?

Also if it helps the PHP code that I'm using to run these queries are:

 $task2 = array();
 $task2 = $_SESSION['task2'];

 $task2estimate = array();
 $task2estimate = $_SESSION['estimatedpress2'];

 $task2actual = array();
 $task2actual = $_SESSION['actualpress2'];

 addacutalerror_75($memberid, $task2actual);
 addestimatederror_75($memberid, $task2estimate);

Also to check whether there was data present for $task2actual I had done an echo ..[0], .. [1].. etc and there was data present in the array.

Updated

For those who are searching for solutions and have the same problem, here's what I did:

function addacutalerror_75($memberid, $task2actual) {

$insertmember = "INSERT INTO ibtask_task2_75beep (user_id, Trial1_tone_actual,
    Trial2_tone_actual, Trial3_tone_actual, Trial13_tone_actual,
    Trial14_tone_actual, ..., Trial40_notone_actual) VALUES ('$memberid', '$task2actual[0]', '$task2actual[1]', '$task2actual[3]', '$task2actual[18]', '$task2actual[21]', '$task2actual[22]', '..., '$task2actual[24]', '$task2actual[29]', '$task2actual[33]','$task2actual[38]' )";

mysql_query($insertmember) or die(mysql_error());

}
  • 写回答

1条回答 默认 最新

  • dpm91915 2012-10-28 02:26
    关注

    by the way, UPDATE is very different from INSERT.

    UPDATE - modify the existing record(s) on the table.
    INSERT - adds new record(s) on the table.

    Your query is fine but you are doing update. But you want to insert record not to update record right? The query when you insert record looks like this,

    $updateibtask2 = "INSERT INTO ibtask_task2_75beep 
                         (Trial1_tone_actual, Trial2_tone_actual, 
                          Trial3_tone_actual,...) 
                      VALUES ('$taskerror[0]', '$taskerror[1]',...)";
    

    and your query is vulnerable with SQL Injection. Please take time to read the article below to protect against SQL injection,

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

报告相同问题?

悬赏问题

  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?