Tengo este error en mi archivo settings.php
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\wamp\www\settings.php on line 74
PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\wamp\www\settings.php on line 74
en la linea 74 tengo esto
$statement = $connect->prepare($query);
$statement->execute($data);
if($statement->execute($data))
{
$message = '<div class="alert alert-success">Profile Updated</div>';
}
trate de corregirlo pero no encuentro una solución alguien tiene alguna idea de como arreglar estos errores? y si tienen alguna idea de como mejorar el código me ayudaría mucho
<?php
session_start();
header('Content-Type: text/html; charset=utf-8');
$connect = new PDO('mysql:host=;dbname=;charset=utf8',"","");
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$id = $_SESSION['user_id'];
if(!isset($id))
{
header('location:/');
}
$message = '';
if(isset($_POST['edit_profile']))
{
$file_name = '';
if(isset($_POST['profile_image']))
{
$file_name = $_POST['profile_image'];
}
if($_FILES['profile_image']['name'] != '')
{
if($file_name != '')
{
unlink('img/avatar/'.$file_name);
}
$image_name = explode(".", $_FILES['profile_image']['name']);
$extension = end($image_name);
$temporary_location = $_FILES['profile_image']['tmp_name'];
$file_name = rand() . '.' . strtolower($extension);
$location = 'img/avatar/' . $file_name;
move_uploaded_file($temporary_location, $location);
}
$check_query = "
SELECT * FROM user WHERE usuario = :username AND id != $id
";
$statement = $connect->prepare($check_query);
$statement->execute(
array(
':username' => trim($_POST["username"]),
)
);
$total_row = $statement->rowCount();
if($total_row > 0)
{
$message = '<div class="alert alert-danger">Username Already Exists</div>';
}
else
{
$data = [
':username' => $_POST["username"],
':profile_image' => $file_name,
':bio' => $_POST["bio"]
];
if($_POST['password'] != '')
{
$data = [
':password' => hash('sha512', $_POST["password"])
];
$query = "
UPDATE user SET usuario=:username,pasword=:password,tipo='user',avatar=:profile_image,bio=:bio,bloqueado='0',verify='0' WHERE id = $id
";
}
else
{
$query = "
UPDATE user SET usuario=:username,pasword=:password,tipo='user',avatar=:profile_image,bio=:bio,bloqueado='0',verify='0' WHERE id = $id
";
}
$statement = $connect->prepare($query);
$statement->execute($data);
if($statement->execute($data))
{
$message = '<div class="alert alert-success">Profile Updated</div>';
}
}
}
$query = "SELECT * FROM user WHERE id = $id";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
?>
<html>
<head>
<meta charset="utf-8">
<title>profile</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-3">
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Edit Profile</h3>
</div>
<div class="panel-body">
<?php
foreach($result as $row)
{
echo $message;
?>
<form method="post" enctype="multipart/form-data">
<div class="form-group">
<label>Username</label>
<input type="text" name="username" id="username" pattern="^[a-zA-Z0-9_.-]*$" required class="form-control" value="<?php echo $row["usuario"];?>" />
</div>
<div class="form-group">
<label>Password</label>
<input type="password" name="password" id="password" class="form-control" />
</div>
<div class="form-group">
<label>Profile Image</label>
<input type="file" name="profile_image" id="profile_image" accept="image/*" />
<?php
if($row["avatar"] != '')
{
echo '<img src="img/avatar/'.$row["avatar"].'" class="img-thumbnail" width="150" />';
echo '<input type="hidden" name="profile_image" value="'.$row["avatar"].'" />';
}
?>
</div>
<div class="form-group">
<label>Short Bio</label>
<textarea name="bio" id="bio" class="form-control"><?php echo $row["bio"]; ?></textarea>
</div>
<div class="form-group">
<input type="submit" name="edit_profile" id="edit_profile" class="btn btn-primary" value="Save" />
</div>
</form>
<?php
}
?>
</div>
</div>
</div>
<div class="col-md-3">
</div>
</div>
</div>
</body>
</html>