douao3636
douao3636
2018-03-22 17:47

是什么导致了这个错误? mysqli_stmt :: bind_result():

已采纳

I'm using mysqli_prepare() so the thing is I get this error always.

Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement in download.php on line 12

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'No data supplied for parameters in prepared statement' in ***gg.php:13 Stack trace: #0 \download.php(13): mysqli_stmt->execute() #1

include('.') #2 {main} thrown in

download.php on line 13

I looked up in other questions but I didn't manage to get the solution.

my code :

if(isset($_GET['cert_id'])){

$cert_id = $_GET['cert_id'];
$stmt1 = mysqli_prepare($connection,"SELECT cert_id,certificate_id,name_student,hours_com,course_title FROM cert JOIN courses WHERE cert_id = ? AND course_id = certificate_id");
$stmt1->bind_param("iisss",$cert_id,$certificate_id,$name_student,$hours_com,$course_title);
$stmt1->execute();
while(mysqli_stmt_fetch($stmt1))
{
  $pdf = new \setasign\Fpdi\Fpdi();
  $pdf->addPage('L');
  $pagecount = $pdf->setSourceFile('cert.pdf');
  $tplIdx = $pdf->importPage(1);
  $pdf->useTemplate($tplIdx);
  $pdf->SetY(-120);
  $pdf->SetX(35);
  $pdf->SetFont('times', 'B', 35);
  $pdf->cell(20, 10,$name_student,  'C');
  $pdf->SetY(-135);
  $pdf->SetX(135);
  $pdf->SetFont('times', 'B', 35);
  $pdf->cell(90, 100, $course_title, 'C');
  $pdf->SetY(151);
  $pdf->SetX(200);
  $pdf->AddFont('BOOKOSBI','','BOOKOSBI.php');
  $pdf->SetFont('BOOKOSBI','',25);
  $pdf->cell(40, 10, $hours_com 'C');

}
$pdf->Output('certnew.pdf','D');

}

line 12 & 13 :

$stmt1->bind_param("iisss",$cert_id,$certificate_id,$name_student,$hours_com,$course_title);
$stmt1->execute();

Any idea what is wrong here?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dpw63348 dpw63348 3年前

    The question marks in your query are placeholders for values that you'll add later. The number of them needs to match the number of parameters you're binding -- that's where the values come from. However, in your example, you've got one question mark but then you try to bind five parameters:

    $stmt1 = mysqli_prepare(
        $connection,
        "SELECT ... FROM cert JOIN courses WHERE cert_id = ? AND course_id = certificate_id"
    );
    $stmt1->bind_param(
        "iisss",
        $cert_id, certificate_id, $name_student, $hours_com, $course_title
    );
    

    You seem to want this:

    $stmt1->bind_param("i",$cert_id);
    
    点赞 评论 复制链接分享

相关推荐