【发布时间】:2016-04-19 08:58:46
【问题描述】:
我正在尝试将当前时间戳添加到 php 中的图像路径中,并将图像路径存储到 MySQL 中。我从谷歌搜索并看到insert_time=now()。我尝试编写代码,但我的 php 出现错误。
<?php
if( $_SERVER['REQUEST_METHOD']=='POST' ){
if( !empty( $_POST['listItems'] ) ){
$mysqli = new mysqli("127.0.0.1:3307", "root", "", "androiddb");
if( $mysqli->connect_errno ) echo "Failed to connect to MySQL";
$image = $_POST['image'];
$listItems = json_decode( $_POST['listItems'], true );
$sql="SELECT id FROM staff_benefit ORDER BY id ASC";
$id=1;
$res=$mysqli->query( $sql );
while( $rs=$res->fetch_object() ) $id=$rs->id;
$path=NOW()."$id.png";
$actualpath="http://192.168.107.115:80/Android/CRUD/PhotoUpload/$path";
$sql="INSERT INTO `staff_benefit` ( `type`, `amount`, `description`, `image`, `ts_id` ) VALUES ( ?, ?, ?, ?, ? )";
$stmt=$mysqli->prepare( $sql );
$pathelements=array( realpath( $_SERVER['DOCUMENT_ROOT'] ), 'CRUD', 'PhotoUpload', '' );
$savepath = realpath( implode( DIRECTORY_SEPARATOR, $pathelements ) ) . "{$id}.png";
$bytes=file_put_contents( $savepath, base64_decode( $image ) );
if( !$bytes ){
echo 'Error saving image';
}
if ( $stmt && $bytes) {
foreach( $listItems as $item ){
$stmt->bind_param('sssss', $item['type'], $item['amount'], $item['description'], $actualpath, $item['ts_id'] );
$res=$stmt->execute();
if( !$res ) echo 'Query failed with code: '.$stmt->errno;
}
}
$mysqli->close();
}
}
?>
错误
call to undefined function Now()
似乎 Now() 不存在 :( .
【问题讨论】:
-
我很好奇为什么这里的人喜欢关闭人的问题?您可以将我的问题标记为重复但无需投票关闭问题:) 并且提供的链接没有更多帮助:)
-
如果您认真询问,请尝试meta.stackoverflow.com -- 我无法快速找到确切原因的问题,但这个问题涵盖了(以及更多):meta.stackexchange.com/questions/10841/…
-
@tripleee 好的,谢谢先生 :)