我有一個函數,人們可以在數據庫中插入兩個文本字段。它插入空字段到在時刻數據庫在給我的這些錯誤現在:插入數據庫時未定義的索引
注意:未定義的變量:流行語在/Applications/XAMPP/xamppfiles/htdocs/modul8B/controllers/home.php線路17
注意:未定義的變量:行中/Applications/XAMPP/xamppfiles/htdocs/modul8B/controllers/home.php興趣17
說明:未定義變量:圖像/應用程序/ XAMPP/xamppfiles/htdocs中/ modul8B /控制器/ home.php在線17
以下是表格:
<?php
include_once 'models/profile_table_class.php';
return"
<div class='main-wrap'>
<div class='container'>
<div class='header'>
<form id='profile-form' method=post action='index.php?page=home' enctype='multipart/form-data'>
<h1> Your Profile </h1>
<textarea name='catchphrase' id='catchphrase'>
</textarea>
<textarea name='interest' id='about-you' >
</textarea>
<h3 class='upload-heading'>Upload Image:</h3>
<input type='file' name='image' id='file'>
<input id='profile-submit' type='submit' value='profile-submit'/>
</form>
</div>
</div>
</div>
";
下面是插入數據的腳本:
class Profile_Table {
private $db;
public function __construct($pdo) {
$this->db = $pdo;
;
}
public function insertProfile($catchphrase, $interest, $image){
$sql = "INSERT INTO profile (catchphrase, interest, image) Values ('".$catchphrase."', '".$interest."', '".$image."')";
$statement = $this->db->prepare($sql);
$data = array ($catchphrase, $interest, $image);
$statement->execute ($data);
return $statement;
}
這裏的地方錯誤是來自代碼:
include_once "models/profile_table_class.php";
$profile = new Profile_Table($db);
$profileIsSubmitted = isset($_POST['profile-submit']);
if ($profileIsSubmitted) {
$catchphrase = $_POST ['catchphrase'];
$interest = $_POST ['interest'];
$image = $_POST ['image'];
} try {
$profile->insertProfile($catchphrase, $interest, $image);
} catch (Exception $e) {
$errorDescription = $e;
echo $e;
}
任何幫助表示讚賞。
把db字段和表名反引號或單引號 –
爲什麼'$ _POST ['?不知道這是否會導致錯誤。你可以做'var_dump($ _ POST);'只是爲了檢查你的值是否正確發送。 –