我正在使用 PHP 表单来更新数据库记录。我对大多数记录都没有问题,但是我需要将 html 放入其中。如果我只输入常规文本或单引号,它会更新,但如果我输入双引号或其他 HTML,它不会。
这是我的页面
<?php
//start session
session_start();
$hostname_DuskySportCenter = "localhost";
$database_DuskySportCenter = "test";
$username_DuskySportCenter = "test";
$password_DuskySportCenter = "test";
$con=mysqli_connect($hostname_DuskySportCenter,$username_DuskySportCenter,$password_DuskySportCenter,$database_DuskySportCenter);
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//update a record
mysqli_query($con,"UPDATE CSINSTOCK SET name=\"{$_POST['name']}\", description=\"{$_POST['description']}\" WHERE id=9999 ");
//get record set
$result = mysqli_query($con,"SELECT * FROM `CSINSTOCK` WHERE `id` = '9999' ");
echo '<form action="monthly-specials-cs-update.php" method="post">';
//table heading row
echo '<table width="1000" border="1" cellspacing="0" cellpadding="1">';
echo '<tr>';
echo '<td>ID</td>';
echo '<td>NAME</td>';
echo '<td>description</td>';
echo '<td>sort</td>';
echo '<td>active</td>';
echo '<td>sold</td>';
echo '<td>message</td>';
echo '<td>price</td>';
echo '<td>financing</td>';
echo '<td>img1</td>';
echo '<td>img2</td>';
echo '<td>img3</td>';
echo '<td>img4</td>';
echo '<td>img5</td>';
echo '<td>img6</td>';
echo '<td>img7</td>';
echo '<td>img8</td>';
echo '<td>img9</td>';
echo '<td>img10</td>';
echo '</tr>';
//display data
while($row = mysqli_fetch_array($result))
{
echo '<tr>';
echo '<td>'. $row['id'] . '</td>';
echo '<td><input type="text" name="name" value="' . $row['name'] . '" /> </td>';
echo '<td><textarea name="description" value="' . $row['description']. '">' . $row['description'] .'</textarea></td>';
echo '<td><input type="text" name="sort" value="' . $row['sort'] . '" /> </td>';
echo '<td><input type="text" name="active" value="' . $row['active'] . '" /> </td>';
echo '<td><input type="text" name="sold" value="' . $row['sold'] . '" /> </td>';
echo '<td><input type="text" name="message" value="' . $row['message'] . '" /> </td>';
echo '<td><input type="text" name="price" value="' . $row['price'] . '" /> </td>';
echo '<td><input type="text" name="financing" value="' . $row['financing'] . '" /> </td>';
echo '<td><input type="text" name="img1" value="' . $row['img1'] . '" /> </td>';
echo '<td><input type="text" name="img2" value="' . $row['img2'] . '" /> </td>';
echo '<td><input type="text" name="img3" value="' . $row['img3'] . '" /> </td>';
echo '<td><input type="text" name="img4" value="' . $row['img4'] . '" /> </td>';
echo '<td><input type="text" name="img5" value="' . $row['img5'] . '" /> </td>';
echo '<td><input type="text" name="img6" value="' . $row['img6'] . '" /> </td>';
echo '<td><input type="text" name="img7" value="' . $row['img7'] . '" /> </td>';
echo '<td><input type="text" name="img8" value="' . $row['img8'] . '" /> </td>';
echo '<td><input type="text" name="img9" value="' . $row['img9'] . '" /> </td>';
echo '<td><input type="text" name="img10" value="' . $row['img10'] . '" /> </td>';
echo '</tr>';
}
//closing tag for table
echo '</table>';
echo '<br /><input type="submit" value="submit" /></form>';
mysqli_close($con);
?>