我究竟做错了什么?我知道事实与准备好的陈述有关。谢谢!
编辑:这是脚本的所有代码,所以每个人都可以看到发生了什么。我现在必须添加更多单词,因为表单不喜欢我添加的代码量。
<? if($_SERVER['REQUEST_METHOD'] == "POST"){
include_once("includes/connect.php");
session_start();
$error = array();
$success = "The artist has been added!";
if(!empty($_POST['artist-name'])){
$artistName = $_POST['artist-name'];
} else{
$error[] = "Please enter a valid artist name!";
}
if(empty($error)){
//prepared statement goes here "INSERT INTO artist VALUES(?)"
try{
$pdo = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $pdo->prepare("INSERT INTO artist(name) VALUES(:artist)");
$stmt->execute(array("artist" => $artistName));
while($row = $stmt->fetch()) {
print_r($row);
}
} catch(PDOException $e){
echo $e->getMessage();
}
//$_SESSION["success"] = $success;
} else {
$_SESSION["error"] = $error;
}
header("Location: ../add-artist.php");
exit();
}
?>