首页 > 解决方案 > 我的 Html 表单没有被插入到数据库中并且没有显示错误消息

问题描述

我在将此 HTML 表单中的数据插入 MySQL 时遇到了挑战。没有引发错误,但数据未显示在数据库表中。我在数据库中有其他表,它们使用相同的方法从其他表单接收值,并且工作正常。

此外,我已经通过在插入语句中的每个列名周围使用反引号来检查关键字被用作列名的可能性,但问题仍然没有得到解决。

感谢您的意见和支持。

HTML 表单

<?php
// Initialize the session
session_start();
 
// Check if the user is logged in, if not then redirect him to login page
if(!isset($_SESSION["loggedin"]) || $_SESSION["loggedin"] !== true){
    header("location: login.php");
    exit;
}
?>

<!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.0">
    <title>Document</title>
    <link rel="stylesheet" href="style3.css">
    
</head>
<body>
    <div class="container">
        <div id="BigForm1">
        <form action="connect3.php" method="POST" id="Form1" name="Form1">
            
            <h3>Profile and Skills Section</h3>
            
            <textarea type="text" placeholder="Profile" id="profile" name="profile" ></textarea>
            <input type="text" placeholder="Top Skill 1" id="firstSkill" name="firstSkill" >
            <input type="text" placeholder="Top Skill 2" id="secondSkill" name="secondSkill" >
            <input type="text" placeholder="Top Skill 3" id="thirdSkill" name="thirdSkill"  >
            <input type="text" placeholder="Top Skill 4" id="fourthSkill" name="fourthSkill" >
            <div class="btn-box">
            <button type="submit" id="Next1">Submit</button>
            </div>
        </form>
        </div>
       
    </div>
</body>
</html>

这是插入文件的内容

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

    session_start();
    //Sppecial User Tracker
    $userID2 = $_SESSION["id"];


    /*Profile information**/
    $profile = $_POST['profile'];
    $skill1 = $_POST['firstSkill'];
    $skill2 = $_POST['secondSkill'];
    $skill3 = $_POST['thirdSkill'];
    $skill4 = $_POST['fourthSkill'];

    

    $conn = new mysqli('localhost', 'root', '', 'project');
    if($conn->connect_error){
        die('Connection Failed : '.$conn->connect_error);
    }else{
        /*About Information*/ 
       
        $stmt = $conn->prepare("insert into about2(FullName, Skill1, Skill2, Skill3, Skill4)
            values(?, ?, ?, ?, ?)");
            
            $stmt->bind_param("sssss",$about, $skill1, $skill2, $skill3, $skill4);
            $stmt->execute();
            $stmt->close();
            
            header("location: generated.php");
    }
    
?>

标签: phphtml

解决方案


你的代码:

<?php 
...
$stmt->bind_param("sssss",**$about**, $skill1, $skill2, $skill3, $skill4); 
...
?>

问题修复代码:

<?php 
...
$stmt->bind_param("sssss",**$profile**, $skill1, $skill2, $skill3, $skill4);
...
?>

问题有:您尝试插入undefined变量,查看您的代码$about变量未定义。


推荐阅读