【发布时间】:2014-04-01 12:37:16
【问题描述】:
我有一个功能,人们可以将两个文本字段插入数据库。它现在将空字段插入数据库中给我这些错误:
注意:未定义变量:第 17 行 /Applications/XAMPP/xamppfiles/htdocs/modul8B/controllers/home.php 中的标语
注意:未定义变量:第 17 行的 /Applications/XAMPP/xamppfiles/htdocs/modul8B/controllers/home.php 感兴趣
注意:未定义变量:第 17 行 /Applications/XAMPP/xamppfiles/htdocs/modul8B/controllers/home.php 中的图像
这是表格:
<?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;
}
任何帮助表示赞赏。
【问题讨论】:
-
将数据库字段和表名放在反引号或单引号中
-
为什么
$_POST [之间有空格?不确定这是否会导致错误。您可以发送var_dump($_POST);来检查您的值是否正确发送。