mysqli
插入我的行为很奇怪。在Windows(localhost开发PC)上工作正常,但在Linux(共享主机)上,它没有按预期工作。
我将字段height
定义为VARCHAR(10)
。使用SELECT
语句读取数据时:
5' 6"
显示为5\' 6\"
表格结构:
CREATE TABLE IF NOT EXISTS `user_details` (
`uname` varchar(20) NOT NULL,
`height` varchar(10) NOT NULL,
`body_type` varchar(20) NOT NULL,
`hair_color` varchar(20) NOT NULL,
`eye_color` varchar(20) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`uname`),
UNIQUE KEY `uname` (`uname`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
读取数据的代码
$statement = $mysqli->prepare("SELECT * from user_details WHERE uname = ?");
$statement->bind_param("s", $uname);
$statement->execute();
if ($statement->bind_result($uname, $height, $body, $hair, $eye, $desc) && $statement->fetch())
{
// work with data.
}
用于INSERT的代码
save_data.php
$statement = $mysqli->prepare("INSERT INTO user_details VALUES(?, ?, ?, ?, ?, ?)");
$statement->bind_param("ssssss", $_POST['uname'], $_POST['height'], $_POST['body'], $_POST['hair'], $_POST['eye'], $_POST['description']);
if ($statement->execute())
{
echo "<div>Username successfully added</div>";
}
save_data.html
<form method="POST" enctype="multipart/form-data">
<table>
<tr><td>Name (Must be unique) : </td><td><input type="text" name="uname"></td></tr>
<tr><td>Profile Image : </td><td><input type="file" name="pic"></td></tr>
<tr><td>Height : </td><td><input type="text" name="height"></td></tr>
<tr><td>Body Type: </td><td><input type="text" name="body"></td></tr>
<tr><td>Hair Color: </td><td><input type="text" name="hair"></td></tr>
<tr><td>Eye Color: </td><td><input type="text" name="eye"></td></tr>
<tr><td>Description: </td><td><textarea name="description" rows="5"></textarea></td></tr>
<tr><td colspan="2"><input type="submit" value="Save New User"></td></tr>
</table>
</form>
在Linux vs Windows上显示
的Linux
窗
答案 0 :(得分:2)
检查服务器以查看是否设置了magic_quotes。如果(我怀疑他们是),请关闭它们。