PHP noob,一直在关注教程,并且明显将其编辑为我的网站规范。现在当我去更新时,我收到以下错误
注意:未定义的索引:第34行的D:\ xampp \ htdocs \ giggedin \ edit.php中的band_id
第34行是:
$stmt->execute(array($_POST['band_id'], $_POST['email'], $_POST['bandname'], $_POST['bandpic'], $_POST['bio'], $_POST['state'], $_POST['genre'], $_POST['link'], $_POST['sound']));
当我删除band_id
时,我收到以下错误:
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:绑定变量数与第34行D:\ xampp \ htdocs \ giggedin \ edit.php中的令牌数不匹配
以下是更新代码(edit.php):
<?php
require_once('includes/connection.php');
// initialize flags
$OK = false;
$done = false;
// get details of selected record
//if (isset($_GET['band_id']) && !$_POST) {
if (isset($_GET['band_id'])) {
// prepare SQL query
$sql = 'SELECT band_id, email, bandname, bandpic, bio, state, genre, link, sound FROM submit
WHERE band_id = ?';
$stmt = $conn->prepare($sql);
// bind the results using numbers to reference the columns used in the select statement
$stmt->bindColumn(1, $band_id);
$stmt->bindColumn(2, $email);
$stmt->bindColumn(3, $bandname);
$stmt->bindColumn(4, $bandpic);
$stmt->bindColumn(5, $bio);
$stmt->bindColumn(6, $state);
$stmt->bindColumn(7, $genre);
$stmt->bindColumn(8, $link);
$stmt->bindColumn(9, $sound);
// execute query by passing array of variables
$OK = $stmt->execute(array($_GET['band_id']));
$stmt->fetch();
}
// if form has been submitted, update record
if (isset($_POST['update'])) {
// prepare update query
$sql = 'UPDATE submit SET email = ?, bandname = ?, bandpic = ?, bio = ?, state = ?, genre = ?, link = ?, sound = ?
WHERE band_id = ?';
$stmt = $conn->prepare($sql);
// execute query by passing array of variables
$stmt->execute(array($_POST['band_id'], $_POST['email'], $_POST['bandname'], $_POST['bandpic'], $_POST['bio'], $_POST['state'], $_POST['genre'], $_POST['link'], $_POST['sound']));
$done = $stmt->rowCount();
}
// redirect if $_GET['band_id'] not defined
if ($done || !isset($_GET['band_id'])) {
header('Location: http://localhost/giggedin/search.php');
exit;
}
// display error message if query fails
if (isset($stmt) && !$OK && !$done) {
$error = $stmt->errorInfo();
if (isset($error[2])) {
$error = $error[2];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="Find a support band for you band with us">
<meta name="author" content="Chris Beechey, Copyright 2016">
<meta name="keywords" content="Music, Australia, Band, Show, Gig">
<link rel="icon" href="">
<title>GIGGEDIN - FIND A BAND</title>
<!--- BOOTSTRAP ------->
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" >
<!--- CSS FOR WHOLE PAGE STYLE -->
<link rel="stylesheet" type="text/css" href="css/styles.css">
<!--- CSS FOR NAV BAR -->
<link rel="stylesheet" type="text/css" href="css/nav.css">
<link rel="stylesheet" type="text/css" href="css/form.css">
<!--- FONTS ------------->
<link href='https://fonts.googleapis.com/css?family=Open+Sans|Oswald|Architects+Daughter' rel='stylesheet' type='text/css'>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<header>
<div id="mySidenav" class="sidenav">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a>
<a href="index.php">Home</a>
<a href="submit.php">Submit Band</a>
<a href="search.php">Search Bands</a>
</div>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">☰ MENU</span>
</header>
<body>
<div class="content">
<div class="container">
<h3>admin only - Edit</h3>
<?php
if (isset($error)) {
echo "<p class='warning'>Error: $error</p>";
}
if($band_id == 0) { ?>
<p class="warning">Invalid request: record does not exist.</p>
<?php } else { ?>
<form role="form" method="post" action="">
<fieldset>
<div class="form-group row">
<label for="email" class="col-sm-2 form-control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="email" name="email" value="<?php echo htmlentities($email); ?>" />
</div>
</div>
<div class="form-group row">
<label for="bandname" class="col-sm-2 form-control-label">Band Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="bandname" name="bandname" value="<?php echo htmlentities($bandname); ?>" />
</div>
</div>
<div class="form-group row">
<label for="bandpic" class="col-sm-2 form-control-label">Band Photo</label>
<div class="col-sm-10">
<input type="file" id="bandpic" name="bandpic" value="<?php echo htmlentities($bandpic); ?>" />
</div>
</div>
<div class="form-group row">
<label for="bio" class="col-sm-2 form-control-label">Brief Bio</label>
<div class="col-sm-10">
<textarea name="bio" class="form-control" id="bio" rows="5" value="<?php echo htmlentities($bio); ?>" /></textarea>
</div>
</div>
<div class="form-group row">
<label for="state" class="col-sm-2 form-control-label">State</label>
<div class="col-sm-10">
<select name="state" class="form-control" id="state" value="<?php echo htmlentities($state); ?>" />
<option></option>
<option value="QLD">QLD</option>
<option value="SA">SA</option>
<option value="VIC">VIC</option>
<option value="WA">WA</option>
<option value="TAS">TAS</option>
<option value="NSW">NSW</option>
<option value="NT">NT</option>
<option value="ACT">ACT</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="genre" class="col-sm-2 form-control-label">Genre</label>
<div class="col-sm-10">
<select name="genre" class="form-control" id="genre" value="<?php echo htmlentities($genre); ?>" />
<option></option>
<option value="rock">ROCK</option>
<option value="punk">PUNK</option>
<option value="blues">BLUES</option>
<option value="bluesrock">BLUES/ROCK</option>
<option value="metal">METAL</option>
<option value="jazz">JAZZ</option>
<option value="acoustic">ACOUSTIC</option>
<option value="solo">SOLO</option>
</select>
</div>
</div>
<div class="form-group row">
<label for="link" class="col-sm-2 form-control-label">FB/Website Link:</label>
<div class="col-sm-10">
<input type="url" class="form-control" id="link" name="link" size="30" value="<?php echo htmlentities($link); ?>" />
</div>
</div>
<div class="form-group row">
<label for="sound"class="col-sm-2 form-control-label">Sound/Video Link:</label>
<div class="col-sm-10">
<input type="url" class="form-control" id="sound" name="sound" size="30" value="<?php echo htmlentities($sound); ?>" />
</div>
</div>
<input type="submit" name="update" value="update" class="submit" />
</fieldset>
</form>
<?php } ?>