以下为我工作:
我必须指出,您不能将其
$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(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)