gpt4 book ai didi

PHP 错误 "parameter was not defined"

转载 作者:太空宇宙 更新时间:2023-11-03 12:10:14 25 4
gpt4 key购买 nike

我正在尝试与一个 friend 一起制作一个简单的上传表单,但我现在卡住了。这是我的麻烦:

我做了这个表格:

screenshot

这是代码:

<form method="post" class="form-horizontal" role="form" action="../i/insert.php" enctype="multipart/form-data">

<div class="form-group">
<label class="col-lg-2 control-label">Title</label>
<div class="col-lg-10">
<input name="v" id="title" type="text" class="form-control" placeholder="Banana nation">
</div>
</div>

<div class="form-group">
<label class="col-lg-2 control-label">Uploader's name</label>
<div class="col-lg-10">
<input name="name" id="upname" type="text" class="form-control" placeholder="Onision">
</div>
</div>

<div class="form-group">
<label class="col-lg-2 control-label">Description</label>
<div class="col-lg-10">
<textarea name="description" id="description" class="form-control" rows="3" placeholder="We are not robots, we are not slaves, we are banana nation."></textarea>
</div>
</div>

<div class="form-group">
<label for="exampleInputFile" class="col-lg-2 control-label">Video thumbnail</label>
<div class="col-lg-10">
<input type="file" id="thumbnail" name="thumbnail">
<p class="help-block">Click to upload your file.</p>
</div>
</div>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>

此表单对../i/insert.php 有一个操作,这是代码(insert.php):

<?php
require('db.php');


$dossier = '/var/www/vids/m/';
$file = basename($_FILES['thumbnail']['name']);
$thmb_name = basename($_FILES['thumbnail']['name']);
$taille_maxi = 3145728;
$taille = filesize($_FILES['thumbnail']['tmp_name']);
$extensions = array('.png', '.jpg', '.jpeg');
$extension = strrchr($_FILES['thumbnail']['name'], '.');

if(!in_array($extension, $extensions))
{
$erreur = 'You can only upload a png, jpg or a jpeg file.';
}
if($taille>$taille_maxi)
{
$erreur = 'Hng.. it\'s too big sen-senpai.., it must be smaller than 3 mb...';
}
if(!isset($erreur))
{

$file = strtr($file,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$file = preg_replace('/([^.a-z0-9]+)/i', '-', $file);
if(move_uploaded_file($_FILES['thumbnail']['tmp_name'], $dossier . $file))
{
$thmb_result = 'Upload succesfull !';
}
else
{
$thmb_result = 'Upload failed !';
}
}
ajout($_POST['v'], $_POST['name'], $_POST['description'], $_POST['description'], $file);
function ajout($v, $name, $description, $fichier, $file)
{
global $bdd;
$req = $bdd->prepare('INSERT INTO `vids`.`vidinfos` (`v`, `name`, `date`, `description`, `fichier`, `file`, `id`) VALUES (:v, :name, CURRENT_DATE(), :description, :fichier, :file, NULL);');
$req->execute(array(
':v' => $v,
':name' => $name,
':description' => $description,
':fichier' => $fichier,
':thmb_name' => $file
));
}
$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

数据库结构如下: enter image description here

所以我填写了表格,图片成功上传到我请求的目录中,但我的数据库中没有显示任何内容,没有新条目。我使用 var_dump 检查了每个变量是否正确定义。

另外,我的 PHP 错误日志中出现了这个错误:

[Wed Jul 09 15:57:52 2014] [error] [client 10.0.0.1] PHP Warning:  PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined on line 48

最佳答案

您正在指定参数 file 但将其绑定(bind)为 thmb_name。它们应该是相同的参数。

关于PHP 错误 "parameter was not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24657194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com