2014-12-28 51 views
0

我情况下,下列类型的代码必须插入一个表格:插入双引号到MySQL,并打印出来没有反斜杠

<iframe src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3035.058400512634!2d-3.6438669999999997!3d40.473973!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd422eea55d33c51%3A0x3294408e8e67eff4!2sClinica+Dental+Artidental!5e0!3m2!1ses!2ses!4v1419779677798" width="600" height="450" frameborder="0" style="border:0"></iframe> 

我追赶公布值如下:

$mapLink = htmlspecialchars($_POST['mapLink'], ENT_QUOTES); 

和iframe,插入如下:

&lt;iframe src=\&quot;https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3035.058400512634!2d-3.6438669999999997!3d40.473973!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0xd422eea55d33c51%3A0x3294408e8e67eff4!2sClinica+Dental+Artidental!5e0!3m2!1ses!2ses!4v1419779677798\&quot; width=\&quot;600\&quot; height=\&quot;450\&quot; frameborder=\&quot;0\&quot; style=\&quot;border:0\&quot;&gt;&lt;/iframe&gt; 

我怎样才能以接回我怎么做nitial链接"<iframe src..."用php打印出来,因为它是最初写的?如果没有反斜杠,& QUOT等

更新1

这是我如何插入/更新的MYSQL:

  $editCentro = $con->prepare("UPDATE centros SET active = :active, nombre = :nombre, zona = :zona, address = :address, 
     metro = :metro, zip = :zip, phone = :phone, fax = :fax, email = :email, mapLink = :mapLink, descripcion = :descripcion, horarios = :horarios 
     WHERE id = ".$centroId); 
     $editCentro->execute(array(':active'=>$active, ':nombre'=> $nombre, ':zona'=>$zona, ':address'=>$address, ':metro'=>$metro, 
     ':zip'=>$zip, ':phone'=>$telefono, ':fax'=>$fax, ':email'=>$email, ':mapLink'=>$mapLink, ':descripcion'=>$descripcion, ':horarios'=>$horarios)); 

而且即使不逃逸的价值,它被插了在双引号之前加上反斜杠...

+0

如果您需要原始值,您为什么首先将它转义出来? 'htmlspecialchars'不适用于数据库引用。 – mario

+0

您需要了解实际转义的含义。然后你需要禁用魔术引号。 – SLaks

+0

@mario我逃跑,因为否则双引号与我的PHP搞砸了,并停止插入截断整个值 – samyb8

回答

1

将字符串分配给$mapLink时转义字符串:

$mapLink = htmlspecialchars($_POST['mapLink'], ENT_QUOTES); 

如果你想将它插入到数据库中,不被简单地从后采取的价值,逃避它。 (同样,这不是逃逸你会用它来防止SQLI)

防止SQL注入,用mysql像这样绑定:

$stmt = $mysqli->prepare("INSERT INTO sometable (fieldA, mapField, fieldC) VALUES (?, ?, ?)"); 
$stmt->bind_param('sss', $someVar, $mapLink, $otherVar); 

查看参数的详细信息结合in the PHP docs here

如果你有魔术引号的问题,你可以带他们像这样:

$mapLink = stripslashes($_POST['mapLink']); 
+0

当我直接插入到数据库中时,它在双引号之前出现反斜杠....并且正在准备并使用数组执行 – samyb8

+0

@ samyb8请将用于将其插入数据库的代码发布出去。如果你从'$ _POST ['mapLink']'绑定了一个没有修改的值,反斜杠就不应该在那里。 – Sebi

+0

当然,请参阅更新1 – samyb8

0

你试过html_entity_decode

<?php 
$orig = "I'll \"walk\" the <b>dog</b> now"; 

$a = htmlentities($orig); 

$b = html_entity_decode($a); 

echo $a; // I'll &quot;walk&quot; the &lt;b&gt;dog&lt;/b&gt; now 

echo $b; // I'll "walk" the <b>dog</b> now 
?>