PHP/MySQLremove 来自 echo 的单引号
PHP/MySQLremove single quotes form echo
我正在尝试从公司列表中回复。
但我无法摆脱单引号?
我在网上发现了很多这样的问题,但是 none 有效...
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>
我也想知道,为什么只有 "customer_name" 设置了两次才能回显?
它只用这段代码回显一次。
提前致谢!
使用str_replace()
函数替换字符串中的单引号(''):
使用这个:str_replace("'","",$string);
但是对于问题的确切解决方案,请将您的代码放在这里。
我想这就是你想要的
你在 $query
变量上替换单引号
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
}
?>
我正在尝试从公司列表中回复。 但我无法摆脱单引号? 我在网上发现了很多这样的问题,但是 none 有效...
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>
我也想知道,为什么只有 "customer_name" 设置了两次才能回显? 它只用这段代码回显一次。
提前致谢!
使用str_replace()
函数替换字符串中的单引号(''):
使用这个:str_replace("'","",$string);
但是对于问题的确切解决方案,请将您的代码放在这里。
我想这就是你想要的
你在 $query
变量上替换单引号
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
}
?>