การอ่านฟิลด์ TEXT (ไม่ใช่ VARCHAR) จาก MySQL ด้วย PHP ไม่แสดงในพื้นที่ข้อความ HTML

ฉันกำลังพยายามสร้างหน้าแก้ไขที่อ่านข้อมูลจาก MySQL ด้วย PHP แล้วแสดงในรูปแบบ HTML\nฟิลด์ปกติ เช่น VARCHAR แสดงได้อย่างถูกต้อง แต่ฉันประสบปัญหาในการแสดงฟิลด์ TEXT

\n
<?php\n    $DATABASE_HOST = \'\';\n    $DATABASE_USER = \'\';\n    $DATABASE_PASS = \'\';\n    $DATABASE_NAME = \'\';\n   \n    mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);\n    $mysqli = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);\n    if ( mysqli_connect_errno() ) {\n        exit(\'Failed to connect to MySQL: \' . mysqli_connect_error());\n    }\n       \n    $idjob = $_POST[\'jobID\']; \n    $jobquery = $mysqli->prepare(\'SELECT * FROM jobs WHERE id = ?\');\n    $jobquery->bind_param(\'s\', $idjob); // \'s\' specifies the variable type => \'string\'\n\n    $jobquery->execute();\n\n    $jobresult = $jobquery->get_result();\n    while ($row = $jobresult->fetch_assoc()) {\n        $jobtitle = $row[\'jobtitle\'];\n        $workhours = $row[\'workhours\'];\n        $type = $row[\'type\']; \n        $availfrom = $row[\'availfrom\'];\n        $deadline = $row[\'deadline\'];              \n        $customer = $row[\'customer\'];\n        $province = $row[\'province\'];\n        $town = $row[\'town\'];        \n        $minreq = $row[\'minreq\'];\n        $posdetails = $row[\'posdetails\'];\n        $minsal = $row[\'minsal\'];\n        $maxsal = $row[\'maxsal\'];\n    }\n    mysqli_free_result($jobresult);\n    mysqli_close($mysqli);\n\n?>\n<!DOCTYPE html>\n\n<html lang="en">\n    <head>\n        <title>Edit Job Listing</title>\n        <link rel="shortcut icon" type="image/jpg" href="images/Logo.jpg">\n        <meta charset="UTF-8">\n        <meta name="viewport" content="width=device-width, initial-scale=1.0 shrink-to-fit=no">        \n        <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">\n        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">             \n        <link rel="stylesheet" href="../assets/css/style.css" type="text/css"/>\n    </head>\n    <body id="editjoblisting">\n        <!-- Container (About Add New Job Listing Section) -->\n        <div id="abouteditnewjob" class="container-fluid bg-grey">\n            <div class="row">\n                <div class="col-sm-2"></div>\n                <div class="col-sm-8">\n                    <div class="text-center">\n                        <h2> Edit Job Listing </h2>\n                    </div>\n                </div>\n                <div class="col-sm-2"></div>\n            </div>\n        </div>\n        <div class="container-fluid bg-grey">\n            <form method="post" id="updedit_form" action="../php/updeditjob.php">\n                <div class="form-row">\n                    <div class="col-sm-2"></div>\n                    <div class="col-sm-4">\n                        <div class="form-group">                               \n                            <label for="jobtitle"> Job Title</label>\n                            <input type="text" class="form-control"  name="jobtitle" value=\'<?php echo $jobtitle; ?>\'>                                              \n\n                            <label for="workhours"> Working Hours</label>                            \n                            <input type="text" class="form-control"  name="workhours" value=\'<?php echo $workhours; ?>\'>                            \n\n                            <label for="worktype">Type</label>\n                            <select class="form-control"  name="worktype" >\n                                <option value=\'<?php echo $type; ?>\' selected><?php echo $type; ?></option>\n                                <option>--None--</option>\n                                <option>Temporary</option>\n                                <option>Permanent</option>                                \n                            </select>\n\n                            <label for="availfrom"> Available From</label>                            \n                            <input type="date" class="form-control" id="availfrom" name="availfrom" required maxlength="50" value=\'<?php echo $availfrom; ?>\'>                            \n\n                            <label for="deadline"> Application Deadline</label>                            \n                            <input type="date" class="form-control" id="deadline" name="deadline" required maxlength="50" value=\'<?php echo $deadline; ?>\'>                            \n                        </div>\n                    </div>\n                    <div class="col-sm-4">\n                        <div class="form-group">\n                            <label for="minreq">Minimum Requirements</label>\n                            <textarea class="form-control" type="textarea" name="minreq" id="minreq" maxlength="6000" rows="5" value=\'<?php echo $minreq; ?>\'></textarea>\n\n                            <label for="posdetails">Position Details</label>\n                            <textarea class="form-control" type="textarea" name="posdetails" id="posdetails" maxlength="6000" rows="5" value=\'<?php echo $posdetails; ?>\'></textarea>\n\n                            <label for="minsal"> Minimum Salary</label>                            \n                            <input type="text" class="form-control" id="minsal" name="minsal" value=\'<?php echo $minsal; ?>\'>                            \n\n                            <label for="maxsal"> Maximum Salary</label>                            \n                            <input type="text" class="form-control" id="maxsal" name="maxsal" value=\'<?php echo $maxsal; ?>\'>                            \n                        </div>                        \n                    </div>\n                    <div class="col-sm-2"></div>                        \n                </div>                                                \n            </form>\n        </div>\n    </body>\n</html> \n
\n

นี่คือข้อมูลที่ฉันพยายามแสดง/แก้ไข

\n
 id "251"    \njobid "ID#20101664"\njobtitle "SENIOR CONVEYANCING SECRETARY"    \nworkhours "Monday - Friday 7:00 - 17:00"    \ntype "Permanent"    \navailfrom "2021-06-07"  \ndeadline "2021-10-29"       \n\nminreq  \n"- Matric Certificate\n- Minimum 3 years experience \n- Knowledge in Law programs (Lexis Nexis, Windeed) – Compulsory\n- Knowledge of Bonds: Absa, Standard Bank, FNB and Nedbank\n- Bilingual (English & Afrikaans)\n- Computer literate\n- Be accurate and methodical etc.." \\N  \nminsal "0"  \nmaxsal "0"\n
\n

ทุกอย่างทำงานได้ดียกเว้น minreq ซึ่งเป็นฟิลด์ TEXT ใน MySQL ไม่แสดง แต่เสียงสะท้อนแสดงว่าได้รับในอาร์เรย์ $row แล้ว

\n

Answer

วิธีแก้ปัญหา:

ลองสะท้อนค่าระหว่างแท็ก textarea ไม่ใช่ในแอตทริบิวต์ของค่า:

\n
<textarea class="form-control" type="textarea" name="minreq" id="minreq" maxlength="6000" rows="5"><?php echo $minreq; ?></textarea>\n
\n

Answer

วิธีแก้ไข:

โปรดลบค่าออกจากพื้นที่ข้อความและเขียนโค้ดดังนี้:

\n
//here is the valid code...this will 100% work.\n<textarea class="form-control" type="textarea" name="posdetails" id="posdetails" maxlength="6000" rows="5">\n    <?php echo $posdetails; ?>\n</textarea>\n
\n

Source