我有2个问题,我的第一个问题是我的PHP脚本出错了。它基本上给了我这个
Fatal error: Uncaught Error: Cannot pass parameter 2 by reference in /customers/1/d/9/the-scientist.fr/httpd.www/api/addPost.php:30 Stack trace: #0 {main} thrown in /customers/1/d/9/the-scientist.fr/httpd.www/api/addPost.php on line 30
我的第二个问题是我试图在MariaDB中连续插入一个图像,我想和PHPMyAdmin做同样的事情,以便在BLOB行中插入图像。所以,这是我的PHP脚本:
<?php
try
{
$db = new PDO('mysql:host=the-scientist.fr.mysql;dbname=the_scientist_fr_appli_posts;charset=utf8', 'the_scientist_fr_appli_posts', 'arthur2205');
}
catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// $security = new White\Security;
$post = $_POST;
$img = base64_encode(file_get_contents($_FILES['img']['tmp_name']));
$title = addslashes($post['title']);
$description = addslashes($post['description']);
$fullDesc = addslashes($post['full']);
// if (!empty($title) & !empty($description) & !empty($fullDesc) & !empty($img)) {
// }
// else {
// // header("Location: form.php?error=Fill the form!");
// }
$stmt = $db->prepare("INSERT INTO posts (title, description, img, fullDesc, likes) VALUES (:title, :description, :img, :fullDesc, :likes)");
$stmt->bindParam(':title', $title);
$stmt->bindParam(':description', $description);
$stmt->bindParam(':img', $img);
$stmt->bindParam(':fullDesc', $fullDesc);
$stmt->bindParam(':likes', 0);
$stmt->execute();
// header("Access-Control-Allow-Origin: *");
header("Location: form.php?error=$sql");
此外,这是以下形式:
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionic/1.3.2/css/ionic.min.css">
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<form enctype="multipart/form-data" class="form" id="form" action="./addPost.php" method="POST">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="Titre" class="AddPosttitle" name="title">
</label>
<label class="item item-input">
<input class="description" type="text" placeholder="Mot Clés" maxlength="60" name="description">
</label>
<label class="item item-input">
<div>
<span id='button_upload'>Image : </span>
<input type='file' class="img" name="img">
</div>
</label>
<label class="item item-input">
<textarea placeholder="Description" class="full" name="full"></textarea>
</label>
<div class="padding">
<button class="button button-block button-positive submit-btn" type="submit">
Envoyer
</button>
</div>
</div>
</form>
<style type="text/css">
.form {
background: #FFF;
}
</style>
<?php
if (!empty($_GET['error'])){
?>
<script type="text/javascript">
function findGetParameter(parameterName) {
var result = null,
tmp = [];
var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
tmp = items[index].split("=");
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
return result;
}
alert(findGetParameter("error"));
</script><?php
}
?>
我认为在这一点上,我的问题非常清楚,如果您需要更多信息,请在评论部分询问。
答案 0 :(得分:2)
关于第一个问题:您正在使用:
$stmt->bindParam(':likes', 0);
bindParam()
需要一个参数,一个变量。
如果您只想绑定一个值,则应使用bindValue()
代替:
$stmt->bindValue(':likes', 0);