PHP MYSQL INSERT帮助没有错误

PHP MYSQL INSERT帮助没有错误,第1张

PHP MYSQL INSERT帮助没有错误

以下为我工作:

我必须指出,您不能将其

$postedOn = now();
用作发布当前时间/日期的变量。需要将其输入为
VALUES

IE:

VALUES(:videoId,:username,NOW())";

请注意,我用作

$pdo
连接变量。

<?php$mysql_hostname = 'xxx';$mysql_username = 'xxx';$mysql_password = 'xxx';$mysql_dbname = 'xxx';try {$pdo= new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);      $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $e) {     exit( $e->getMessage() );}$sql = "SELECt MAX(videoId) AS videoId FROM videoinfo";$stmt = $pdo->prepare($sql);   $stmt -> execute(array());$record = $stmt->fetch();$videoID = $record['videoId'];// var_dump($videoID);$username = $_POST['submitter'];try {$sql = "INSERT INTO adminposts        (videoId,username,postedOn)        VALUES(:videoId,:username,NOW())";$stmt = $pdo -> prepare($sql);$stmt -> execute(array(":videoId"=> $videoID,":username"=> $username));}catch(PDOException $e){// $result = "Sorry, an error occurred while editing the database.";// will print a message of the actual error should there be oneprint $e->getMessage();    }


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5640452.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存