如果我的文本中有 space,则无法在文本字段中看到我的数据库中的全部信息

Cannot see the whole information from my database in a text field if i have a space in my text

我的网站有问题,更具体地说,在我的编辑页面中,尤其是在我的编辑文本字段中,它没有在文本字段中显示全部信息。

正如您在图片中看到的,在文本字段中它没有显示全部信息。

我想像在数据库中一样显示它。

忽略第一行...

这是我的代码...

<?php
            $username = $_SESSION["username"];

        if(isset($_POST['id'])){

            $id = $_POST['id'];
            $name = mysql_real_escape_string($_POST["name"]);
            $email = mysql_real_escape_string($_POST["email"]);
            $city = mysql_real_escape_string($_POST["city"]);
            $phone = ($_POST["phone"]);

            $query="UPDATE personal_information
                    SET name = '$name', email = '$email', city = '$city', phone='$phone'
                    WHERE id='$id'";

            mysql_query($query)or die(mysql_error());
            if(mysql_affected_rows()>=0){
                echo "<p>($username) Record Updated<p>";
            }else{
                echo "<p>($username) Not Updated<p>";
            }
        }

        else{
          //first time, initialize as you wish. Probably need to get the first id for this user, using another query
          $id = 0;
        }

        if($query = mysql_query("SELECT name,email,city,phone FROM personal_information WHERE id>'$id' AND username='$username' order by id asc limit 1") or die(mysql_error()))
        {
            if(mysql_num_rows($query)>=1){
                while($row = mysql_fetch_array($query)) {
                $name = $row['name'];
                $email = $row['email'];
                $city = $row['city'];
                $phone = $row['phone'];
                }
            }
            else{
                echo 'No entry found. <a href="javascript:history.back()">Go back</a>';
            }
        }

        ?>

HTML 表单代码...

<form method="post" action="edit_personal_information.php">
    <input type="hidden" name="submitted" value="true" />
        <legend style="color: #F87F25; font: bold 18px Tahoma;">Personal Information</legend>
        <label style="color: #01ACEE; font: bold 12px Tahoma;">Name <input type="text" name="name" value=<?=$name?> required="required" /> </label>
        <br /><br />
        <label style="color: #01ACEE; font: bold 12px Tahoma;">Email <input type="text" name="email" value=<?=$email?> required="required"/> </label>
        <br /><br />
        <label style="color: #01ACEE; font: bold 12px Tahoma;">City <input type="text" name="city" value=<?=$city?> /> </label>
        <br /><br />
        <label style="color: #01ACEE; font: bold 12px Tahoma;">Phone <input type="text" name="phone" value=<?=$phone?> /> </label>
        <br /><br />
    <input type="hidden" name="id" id="id2" value="<?php echo ($id == 0 ? 0 : $id );?>" style="border: 1px solid #006; color:#F87F25; font: bold 16px Tahoma; border-radius:7px; padding:4px;"/>
    <input type="submit" value="Update" id="update" name="submit" style="border: 1px solid #006; color:#F87F25; font: bold 16px Tahoma; border-radius:7px; padding:4px;"/>
    </form>

我能理解问题是它无法显示文本之间的空格,但我找不到解决方案

value=<?=$name?>

如果名字有 space,结果 HTML 将是:

value=Foo Bar

表示该值只有Foo,"Bar"成为不相关的第二个属性。
您需要注意生成正确的 HTML 语法:

value="<?php echo htmlspecialchars($name); ?>"

另请阅读The Great Escapism (Or: What You Need To Know To Work With Text Within Text)