dongre6270 2015-09-22 06:12
浏览 42
已采纳

为什么mysql数据在PHP中显示时会有单引号?

Im new to php and i have this code tested with XAMPP at backend

$name = addslashes ($_POST['name']);
$email = addslashes ($_POST['email']);
$paswd = addslashes ($_POST['paswd']);

$sql = "INSERT INTO webusers (username,email,paswd)VALUES('$name','$email','$paswd')";

and here's my code for displaying data include_once('dbcon.php');

$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";

    }
  ?>

Those code works, except for the data which surprise me why it has a single quote when i show/display it on a table. though i input the data in html . and my magic_quote_gpc was off. is there something i missed or anything wrong with my code? or there is something with my database collation?

i also tried mysql_real_escape_string and mysql_escape_string, nothings change.

thanks for the help.

Otep

  • 写回答

3条回答 默认 最新

  • dshkmamau65777662 2015-09-22 06:16
    关注

    Because you put Single Quotes in the 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";
    
        }
    

    Try that, your code without Single quotes

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度