gpt4 book ai didi

php - 未捕获的 PDOException

转载 作者:行者123 更新时间:2023-11-29 06:53:44 25 4
gpt4 key购买 nike

当我运行以下代码时,出现此错误:

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\pizda\aids\admin\addnew.php:73 Stack trace: #0 on line 73

<?php

error_reporting( ~E_NOTICE ); // avoid notice

require_once 'dbconfig.php';

if(isset($_POST['btnsave']))
{
$NaslovSrpski = $_POST['NaslovSrpski'];
$NaslovEngleski = $_POST['NaslovEngleski'];
$TekstSrpski = $_POST['TekstSrpski'];
$TekstEngleski = $_POST['TekstEngleski'];


$imgFile = $_FILES['user_image']['name'];
$tmp_dir = $_FILES['user_image']['tmp_name'];
$imgSize = $_FILES['user_image']['size'];


if(empty($NaslovSrpski)){
$errMSG = "Please Enter Username.";
}
else if(empty($NaslovEngleski)){
$errMSG = "Please Enter Your Job Work.";
}
else if(empty($TekstSrpski)){
$errMSG = "Please Enter Your Job Work.";
}
else if(empty($TekstEngleski)){
$errMSG = "Please Enter Your Job Work.";
}
else if(empty($imgFile)){
$errMSG = "Please Select Image File.";
}
else
{
$upload_dir = '../uploads/'; // upload directory

$imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension

// valid image extensions
$valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions

// rename uploading image
$userpic = rand(1000,1000000).".".$imgExt;

// allow valid image file formats
if(in_array($imgExt, $valid_extensions)){
// Check file size '5MB'
if($imgSize < 5000000) {
move_uploaded_file($tmp_dir,$upload_dir.$userpic);
}
else{
$errMSG = "Sorry, your file is too large.";
}
}
else{
$errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
}


// if no error occured, continue ....
if(!isset($errMSG))
{
$stmt = $DB_con->prepare('INSERT INTO Obavestenja(NaslovSrpski,NaslovEngleski,TekstSrpski,TekstEngleski, Slika) VALUES(:naslovs, :naslove, :teksts, tekste, :upic)');
$stmt->bindParam(':naslovs',$NaslovSrpski);
$stmt->bindParam(':naslove',$NaslovEngleski);
$stmt->bindParam(':teksts',$TekstSrpski);
$stmt->bindParam(':tekste',$TekstEngleski);
$stmt->bindParam(':upic',$userpic);

if($stmt->execute())
{
$successMSG = "new record succesfully inserted ...";
header("refresh:5;index.php"); // redirects image view page after 5 seconds.
}
else
{
$errMSG = "error while inserting....";
}
}
}
include 'header.php';
?>


<div class="container">


<div class="page-header">
<h1 class="h2">add news. <a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-eye-open"></span> &nbsp; view all </a></h1>
</div>


<?php
if(isset($errMSG)){
?>
<div class="alert alert-danger">
<span class="glyphicon glyphicon-info-sign"></span> <strong><?php echo $errMSG; ?></strong>
</div>
<?php
}
else if(isset($successMSG)){
?>
<div class="alert alert-success">
<strong><span class="glyphicon glyphicon-info-sign"></span> <?php echo $successMSG; ?></strong>
</div>
<?php
}
?>

<form method="post" enctype="multipart/form-data" class="form-horizontal">

<table class="table table-bordered table-responsive">

<tr>
<td><label class="control-label">NaslovSrpski</label></td>
<td><input class="form-control" type="text" name="NaslovSrpski" placeholder="NaslovSrpski" value="<?php echo $NaslovSrpski; ?>" /></td>
</tr>

<tr>
<td><label class="control-label">NaslovEngleski</label></td>
<td><input class="form-control" type="text" name="NaslovEngleski" placeholder="NaslovEngleski" value="<?php echo $NaslovEngleski; ?>" /></td>
</tr>
<tr>
<td><label class="control-label">TekstSrpski</label></td>
<td><textarea class="form-control" type="text" name="TekstSrpski" placeholder="TekstSrpski" value="<?php echo $TekstSrpski; ?>" /></textarea></td>
</tr>
<tr>
<td><label class="control-label">TekstEngleski</label></td>
<td><textarea class="form-control" type="text" name="TekstEngleski" placeholder="TekstEngleski" value="<?php echo $TekstEngleski; ?>" /></textarea></td>
</tr>

<tr>
<td><label class="control-label">Profile Img.</label></td>
<td><input class="input-group" type="file" name="user_image" accept="image/*" /></td>
</tr>

<tr>
<td colspan="2"><button type="submit" name="btnsave" class="btn btn-default">
<span class="glyphicon glyphicon-save"></span> &nbsp; save
</button>
</td>
</tr>

</table>

</form>

最佳答案

您在 tekste 的占位符中缺少“:”:

$stmt = $DB_con->prepare
('INSERT INTO Obavestenja' .
' (NaslovSrpski,NaslovEngleski,TekstSrpski,TekstEngleski, Slika)' .
' VALUES (:naslovs, :naslove, :teksts, :tekste, :upic)');
# ":" was missing here ----------------^

关于php - 未捕获的 PDOException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46514338/

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