此准备好的插入语句的一部分有效,而另一部分则无效,并且我看不到原因,因为我没有收到错误。
我尝试了不同的选择,甚至mysqli也没有赢。 PDO确实包含语句$ dbh-> setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION)
try {
$dbh = new PDO("mysql:host=localhost;dbname=project","root","");
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
echo "Connected successfully";
if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['submit']));
if(
!empty($_POST['skill_level_1'])
&& !empty($_POST['skill_level_2'])
&& !empty($_POST['skill_level_3'])
&& isset($_POST['skill_1'])
&& isset($_POST['skill_experience_1'])
&& isset($_POST['skill_2'])
&& isset($_POST['skill_experience_2'])
&& isset($_POST['skill_3'])
&& isset($_POST['skill_experience_3'])
){
foreach($_POST['skill_level_1'] as $selected) {
$GLOBALS['skill_level_1'] = $selected;
}
foreach($_POST['skill_level_2'] as $selected) {
$GLOBALS['skill_level_2'] = $selected;
}
foreach($_POST['skill_level_3'] as $selected) {
$GLOBALS['skill_level_3'] = $selected;
}
$skill_1 = strip_tags(trim($_POST['skill_1']));
$skill_experience_1 = strip_tags(trim($_POST['skill_experience_1']));
$skill_2 = strip_tags(trim($_POST['skill_2']));
$skill_experience_2 = strip_tags(trim($_POST['skill_experience_2']));
$skill_3 = strip_tags(trim($_POST['skill_3']));
$skill_experience_3 = strip_tags(trim($_POST['skill_experience_3']));
$stmt = $dbh ->prepare("INSERT INTO dbtable
(
skill_level_1, skill_level_2, skill_level_3,
skill_1, skill_experience_1,
skill_2, skill_experience_2,
skill_3, skill_experience_3
)VALUES(
:skill_level_1, :skill_level_2, :skill_level_3,
:skill_1, :skill_experience_1,
:skill_2, :skill_experience_2,
:skill_3, :skill_experience_3
)");
// $stmt->execute(array(':skill_level_1' => $skill_level_1, ':skill_level_2' => $skill_level_2, ':skill_level_3' => $skill_level_3));
$stmt->bindParam(':skill_level_1',$skill_level_1);
$stmt->bindParam(':skill_level_2',$skill_level_2);
$stmt->bindParam(':skill_level_3',$skill_level_3);
$stmt->bindParam(':skill_1',$skill_1);
$stmt->bindParam(':skill_experience_1',$skill_experience_1);
$stmt->bindParam(':skill_2',$skill_2);
$stmt->bindParam(':skill_experience_2',$skill_experience_2);
$stmt->bindParam(':skill_3',$skill_3);
$stmt->bindParam(':skill_experience_3',$skill_experience_3);
$stmt->execute();
echo "Success";
}//end if
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
因此,它适用于部分Skill_level_1,skill_level_2,skill_level_3(复选框)。但是输入框不起作用。我认为带走标签可能会有所作为,但事实并非如此。我尝试了mysqli连接和语句,但也不起作用。
答案 0 :(得分:0)
谢谢你们,我发现了这个问题。 我在输入字段的HTML名称中有一个大写字母。
我还发现它有助于对数据库中的列进行排序,以匹配写入其中的PHP的顺序。这使我能够返回并再次检查HTML。