简体   繁体   中英

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? It only echoes once with this code.

Thanks in advance!

Use str_replace() function to replace single quote('') from the string:

Use this: 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

NOTE : you need to pass the string which is $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

    }
    ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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