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条)

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀