douzhi1879 2013-03-29 15:15
浏览 25
已采纳

无法从PHP插入到mysql Auto Increment行,但可以使用相同的语句从phpmyadmin手动插入

So my problem here is that:

I cannot insert into my auto incremented column from my php

(unless I set the insert values to: '','','','$postdate','posttime').

HOWEVER: When I used the DEBUGGED insert statement below in phpmyadmin, it ran no worries. Therefore there is something preventing my insertion from my php code.

This is my code:

$qinsert    =   "INSERT INTO `post` (text,sender,text_stamp,post_date,post_time) VALUES ('$message','$sender_id','$date','$postdate','$posttime')";
$finsert    =   mysql_query($qinsert);
$postID     =   mysql_insert_id();

This is the output from a debugger:

 Date: Fri, 29 Mar 2013 11:02:53 -0400
 Sender: User's Name 
Message:
 Message Text
 Attachment: 
 Post-Date: 2013-03-29
 Post-Time: 08:02:55

 Q-INSRT: INSERT INTO `post` (text,sender,text_stamp,post_date,post_time) VALUES ('Message Text','User's Name ','Fri, 29 Mar 2013 11:02:53 -0400','2013-03-29','08:02:55')
  F-INST: 
  Post-ID: 
  • 写回答

3条回答 默认 最新

  • duancifu6769 2013-04-03 04:34
    关注

    This did the trick:

    require '../connect.php';
    $email = file_get_contents('php://stdin');
    preg_match_all("/(.*):\s(.*)
    /i", $email, $matches);
    
    $message    = $matches[1][18];
    $message    = str_replace('<HTML><HEAD></HEAD><BODY style="background-color:#ffffff">', '',$message);
    $message    = explode('<',$message);
    $message    = $message[0];
    $sender     = $matches[2][2];
    $sender     = explode('<',$sender); 
    $sender_id  = $sender[0];
    
    mysql_query("INSERT INTO `post` (`text`,`sender`,`text_stamp`,`post_date`,`post_time`) VALUES ('" . mysql_real_escape_string($message) . "','" . mysql_real_escape_string($sender_id) . "','" . mysql_real_escape_string($textdate) . "','$postdate','$posttime')") or die(mysql_error() . "<--There was error processing the query");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料