我得到未定义的索引错误第14行。不知道我在这里错过了什么。我已经看了一段时间了。谢谢你的帮助。不知道怎么会找不到['image]的索引。我已经拿出代码来捕捉错误,希望这部分能够正常工作。
<?php
include 'db.php';
//
$firstname = $conn->real_escape_string(isset($_POST['firstname']) ? $_POST['firstname'] : '');
$lastname = $conn->real_escape_string(isset($_POST['lastname']) ? $_POST['lastname'] : '');
$dob = $conn->real_escape_string(isset($_POST['dob']) ? $_POST['dob'] : '');
$moniker = $conn->real_escape_string(isset($_POST['moniker']) ? $_POST['moniker'] : '');
if (isset($_POST['submitBTN'])) {
$image = $_FILES['image'];
$imageName = $image['image']['name'];
$imageType = $image['image']['type'];
$imageTempName = $image['image']['tmp_name'];
$imageError = $image['image']['error'];
$imageSize = $image['image']['size'];
//get extention
$fileExt = explode('.', $imageName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array("jpg", "jpeg", "png", "pdf", "gif", "GIF");
$fileNameNew = uniqid('', true).".".$fileActualExt;
//Here we define where we want the new file uploaded to
$fileDestination = 'mugshots/'.$fileNameNew;
//And finally we upload the file using the following function, to send it from its temporary location to the uploads folder
move_uploaded_file($imageTempName, $fileDestination);
$query = "INSERT INTO suspects (firstName,lastName,dob,moniker,picture)VALUES(
'$firstname',
'$lastname',
'$dob',
'$moniker',
'$fileDestination')";
if ($conn->query($query) === true) {
echo "New record created successfully";
}
$conn->close();
}
if (isset($_POST['searchBTN'])) {
$query = "SELECT * FROM suspects WHERE firstName = '$firstname' OR lastName = '$lastname' OR dob = '$dob' OR tats = '$tattoo' OR moniker = '$moniker' ";
$result = $conn->query($query);
if ($result->num_rows > 0) {
echo "<table><tr><th>ID</th><th>Name</th><th>AGE</th><th>Tattoo</th><th>Moniker</th></tr>";
// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["id"] . "</td><td>" . $row["firstName"] . " " . $row["lastName"] . "</td><td>" . $row["age"] . "</td><td>" . $row["tats"] . "</td><td>" . $row["moniker"] . "</td></tr>";
}
echo "</table>";
}
else {
echo "0 results";
}
}
?>
我的表格:
<!doctype html>
<html>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div class="form-group">
<form action="subjsearch.php" method="post">
<div class="form-group row">
<label for="fn" class="col-md-1 col-form-label">FirstName:</label>
<div class="col-sm-10">
<input type="text" id="fn" name="firstname">
</div>
</div>
<div class="form-group row">
<label for="ln" class="col-md-1 col-form-label">LastName:</label>
<div class="col-sm-10">
<input type="text" id="ln" name ="lastname">
</div>
</div>
<div class="form-group row">
<label for="bday" class="col-md-1 col-form-label">D.O.B:</label>
<div class="col-sm-10">
<input type="text" id="bday" name="dob" size = "7">
</div>
</div>
<div class="form-group row">
<label for="mn" class="col-md-1 col-form-label">Moniker:</label>
<div class="col-sm-10">
<input type="text" id="mn" name="moniker">
</div>
</div>
<div class="form-group row">
<label for="img" class="col-md-1 col-form-label">Picture:</label>
<div class="col-sm-10">
<input type="file" id="img" name="image">
</div>
</div>
<input type="submit" name="submitBTN" value="Submit">
<input type="submit" name="searchBTN" value="Search">
<input type="reset" name="resetBTN" value="Reset">
</form>
</div>
</body>
</html>
暂无答案!
目前还没有任何答案,快来回答吧!