When a too long text is inserted in mysql, the field gets blank

I’m currently stuck trying to insert a particular type of user input into my MySQL database. I’m creating a form that allows the user to input Title, Requirements, Description, and PowerShell Script code into a database. I need to be able to then display the new input.

I started by converting all my $_POST data into htmlentities before inserting it and everything seemed to be working perfectly. All the short PowerShell scripts were inserting into the database and then displaying appropriately. But, when I tried to insert a long PowerShell script, it just left the table column blank.

    // Create Insert SQL prepared statement
    $insertSql = $pdoConn->prepare('INSERT INTO scripts (ScriptID, script_name, script_requirements, script_description, script_code) VALUES (NULL, :scriptName, :scriptRequirements, :scriptDescription, :scriptCode)');

    // Create htmlentity variable
    $htmlName = htmlentities($_POST['scriptName']);
    $htmlReq = htmlentities($_POST['scriptRequirements']);
    $htmlDesc = htmlentities($_POST['scriptDescription']);
    $htmlCode = htmlentities($_POST['scriptCode']);

    // Execute Insert SQL prepared statement
        'scriptName' => $htmlName,
        'scriptRequirements' => $htmlReq,
        'scriptDescription' => $htmlDesc,
        'scriptCode' => $htmlCode));

    // Display success message and page return
    echo "New script uploaded successfully.<br>";
    echo "<a href='newScript.html'>Upload another script</a><br><br>";

    // Create new query to display new data
    $displaySql = $pdoConn->prepare('SELECT * FROM scripts ORDER BY ScriptID DESC LIMIT 1');

    // Execute SELECT query and display results
    foreach ($displaySql as $row) {
        echo "<button class='accordion'>
              <div class='panel'>
                <p class='requirements-p'>Requirements: ".$row['script_requirements']."</p>
                <p id='description-p'><span>Description: </span>".$row['script_description']."</p>

Leave a Reply

Your email address will not be published.