简体   繁体   English

PHP / MySQL删除单引号回显

[英]PHP/MySQLremove single quotes form echo

I'm trying to echo from a list of Companies. 我正在尝试从公司列表中呼应。 But i cant get rid of the single quotes? 但是我不能摆脱单引号吗? I found a lot of these questions already online, but none worked... 我已经在网上找到了很多这样的问题,但是没有一个起作用。

Code

<div class="form-group">
  <div class="col-sm-12">
    <label>Kunde</label>
        <?php
            $username = $_SESSION['username'];
            $useractive = $_SESSION['id'];
            $query = "SELECT DISTINCT user.id, customer.customer_id, customer.customer_name
                                FROM user JOIN customer ON user.id = customer.customer_id
                                WHERE customer.customer_id=$useractive
                                ORDER BY customer.customer_id";

            $result = mysqli_query($dbc, $query) or die(mysqli_error($dbc));
        ?>
    <select type="text" class="form-control" name="timer_kunde">
      <option></option>
            <?php
                $row = str_replace("'", "", $query);
                while ($row = mysqli_fetch_array($result))
                {
                echo "<option value='".$row['customer_name']."'>'".$row['customer_name']."'</option>";
                }
            ?>
    </select>
  </div>
</div>

I am also wondering, why does the echo only work if the "customer_name" is setup twice? 我也想知道,为什么只有两次设置了“ customer_name”,回声才起作用? It only echoes once with this code. 此代码仅回显一次。

Thanks in advance! 提前致谢!

Use str_replace() function to replace single quote('') from the string: 使用str_replace()函数替换字符串中的单引号(''):

Use this: str_replace("'","",$string); 使用这个: str_replace("'","",$string);

But for the exact solution of the question put your code here. 但是,对于该问题的确切解决方案,请将您的代码放在此处。

I think this is what you want 我想这就是你想要的

your replacing single quotes on $query variable 您在$query变量上替换单引号

NOTE : you need to pass the string which is $row['customer_name'] 注意:您需要传递$row['customer_name']字符串

    <?php
    while($row=mysqli_fetch_array($result))
    {
    $val= str_replace("'","",$row['customer_name']);
    ?>
      <option value="<?php echo $val ?>"><?php echo $val?></option>
    <?php

    }
    ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM