douqian5920 2018-06-27 10:30
浏览 81

插入mysql数据库准备语句

Can anybody see why this is not inputting into my database..

I did have it working, but now i got the error on mysql A form on this field has more than 1000 fields, but none of them do....

here is the prep statment

$db = new PDO("mysql:host=localhost;dbname=class2", 'root', ''); 


$query="INSERT INTO `testdata` (`1st name`, `2nd name`, `title`, `info`, `location`, `phone`, `postcode`, `image`, `image2`, `image3`, `image4`, `image5`, `price`, `catagory`, `cond`, `delivery`, `email`, `username`, `youtubevideo`, `paypal`, `facebook`, `twitter`, `feedbackscore`) 
                         VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";


$stat=$db->prepare($query);

$stat->execute(array("$firstname","$lastname","$sellingtitle","$sellinginfo","$town","$phone1","$postcode","$i0url","$i1url","$i2url","$i3url","$i4url","$price","$catagory","$cond","$delivery","","$sellername","$youtubeurl","$paypal","$facebook","$twitter","feedbackscore"));
  • 写回答

1条回答 默认 最新

  • dsbowmvth16379079 2018-06-27 10:43
    关注

    Your PDO is not prepared correctly.

    $database = new PDO("mysql:host=localhost;dbname=class2", 'root', ''); 
    
    $query = "UPDATE users SET first_name = :first_name, last_name = :last_name
                                                     WHERE user_id = :user_id";
    
    $update = $database->prepare($query);
    $update->execute([
        ':first_name' => $_POST['firstname'],
        ':last_name' => $_POST['lastname'],
        ':user_id' => $_SESSION['user_id'] 
    ]);
    $update->fetch();
    

    With PDO you define the keys of the values in the prepare string like :first_name.

    So then in the execute function's array, you define the values of these keys.

    Hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度