search

Home  >  Q&A  >  body text

Looking for a solution: Parse error: syntax error, unexpected

The following code is saved as wel.php file

<?php

header("content-type:text/html;charset=utf-8");         //设置编码
require 'pdoconfig.php';  //读取公共参数
$dsn = "{$dbType}:host={$host};dbname={$dbName}";  //创建数据源

try{
$pdo = new PDO($dsn,$userName,$password);
$updateTime = time();
$sql = "update grade set name=:name,price=:price,update_time=:update_time where id=10";
$stmt=$pdo ->prepare($sql);
$num = $stmt->execute([':name'=>'php',':price'=>2750,':update_time'=>$updateTime]);
echo '1';

if ($num > 0){
	print '成功的更新了'.$num.'条记录;
}	
}catch (PDOException $e){
	die('操作失败'.$e->getMessage());
}




?>

The following error occurs when running:

Parse error: syntax error, unexpected '操作失败' (T_STRING) in D:\xp.cn\www\wwwroot\admin\localhost_80\wwwroot\pdoupdatepre.php on line 28

Please solve it?

箭1445 days ago2816

reply all(1)I'll reply

  • 天蓬老师

    天蓬老师2021-01-24 17:19:20

    The prompt is very clear, syntax error: there is an extra "}" in line 17, delete

    reply
    0
  • Cancelreply