0

I am having a challenge with inserting data from this HTML form into MySQL. No errors are being thrown but the data does not display in the database table. I have other tables in the database that receiving values from other forms with this same approach and it works fine.

Also, I have checked for the possibility of keywords being used as column names by using backticks around each column name in the insert statement, but the problem still doesn't get solved.

I would appreciate your input and support.

HTML Form

<?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>

Here's the content of the insertion file

<?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");
    }
    
?>
  • What have you tried to resolve the problem? Where are you stuck? – Nico Haase Aug 16 '21 at 09:05
  • 2
    Does https://stackoverflow.com/questions/17053466/how-to-display-errors-for-my-mysqli-query help? – Nico Haase Aug 16 '21 at 09:07
  • You're getting the user id from the session, but you never use it for anything. Shouldn't it be used in the query? You store `$profile = $_POST['profile'];` which you also never use. However, you do bind the variable `$about`, which seems to be undefined. – M. Eriksson Aug 16 '21 at 09:19
  • @MagnusEriksson that's true. Thank you! – Medikal Aug 16 '21 at 09:24
  • @NicoHaase yes I had tried to solve it. Apparently, I was binding a non-existent variable name. Very embarassing! – Medikal Aug 16 '21 at 09:26
  • You should get an error, you have 5 ? and try to insert 6 with bind params. – Grumpy Aug 16 '21 at 10:43

1 Answers1

-1

Your code:

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

Problem fixed code:

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

Problem has: You try to insert undefined variable, look at your code the $about variable is undefined.

ImAtWar
  • 1,023
  • 3
  • 11
  • 23