我是php新手,我在后端用XAMPP测试了这段代码
$name = addslashes ($_POST['name']);
$email = addslashes ($_POST['email']);
$paswd = addslashes ($_POST['paswd']);
$sql = "INSERT INTO webusers (username,email,paswd)VALUES('$name','$email','$paswd')";
这是我显示数据的代码 include_once(' dbcon.php&#39);
$db = mysql_select_db('test');
$sql = "SELECT * FROM webusers";
$result = mysql_query($sql);
$urow = mysql_num_rows($result);
echo"
<table border='1'>
<th>ID</th>
<th>USERNAME</th>
<th>EMAIL</th>
<th>PASSWORD</th>
";
if($result > 0){
while($urow = mysql_fetch_array($result)){
echo "<tr>";
echo" <td class='myinput'>'" .$urow['id']. "'</td>";
echo" <td class='myinput'>'" .$urow['username']. "'</td>";
echo" <td class='myinput'>'" .$urow['email']. "'</td>";
echo" <td class='myinput'>'" .$urow['paswd']. "'</td>";
echo "</tr>";
echo"</table>";
}
}else{
echo"No record";
}
?>
这些代码有效,除了让我感到惊讶的数据,当我在桌子上显示/显示它时,为什么它有一个单引号。虽然我用html输入数据。而且我的magic_quote_gpc已关闭。有什么我错过或我的代码有什么问题?或者我的数据库整理有什么东西?
我也试过mysql_real_escape_string和mysql_escape_string,没有改变。
感谢您的帮助。
OTEP
答案 0 :(得分:0)
您正在HTML标记
中围绕您的值打印'
echo "<tr>";
echo" <td class='myinput'>" .$urow['id']. "</td>";
echo" <td class='myinput'>" .$urow['username']. "</td>";
echo" <td class='myinput'>" .$urow['email']. "</td>";
echo" <td class='myinput'>" .$urow['paswd']. "</td>";
echo "</tr>";
是你真正想要回应的
答案 1 :(得分:0)
因为你把单引号放在HTML中?
echo"
<table border='1'>
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>EMAIL</th>
<th>PASSWORD</th>
</tr>
";
if($result > 0){
while($urow = mysql_fetch_array($result)){
echo "<tr>";
echo" <td class=\"myinput\">" .$urow['id']. "</td>";
echo" <td class=\"myinput\">" .$urow['username']. "</td>";
echo" <td class=\"myinput\">" .$urow['email']. "</td>";
echo" <td class=\"myinput\">" .$urow['paswd']. "</td>";
echo "</tr>";
echo"</table>";
}
}else{
echo"No record";
}
试试,你的代码没有单引号
答案 2 :(得分:0)
试试这个
if($result > 0){
while($urow = mysql_fetch_array($result)){
echo "<tr>";
echo" <td class='myinput'>" .stripslashes($urow['id']). "</td>";
echo" <td class='myinput'>" .stripslashes($urow['username']). "</td>";
echo" <td class='myinput'>" .stripslashes($urow['email']). "</td>";
echo" <td class='myinput'>" .stripslashes($urow['paswd']). "</td>";
echo "</tr>";
echo"</table>";
}
}else{
echo"No record";
}