duanchu9914 2014-12-28 18:43
浏览 63
已采纳

将双引号插入mysql并将其打印出来而不使用反斜杠

I have a form where the following type of code must be inserted:

<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>

I am catching the posted value as follows:

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

And the iframe is inserted as follows:

&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;

How can I do in order to fetch back my initial link "<iframe src..." with php and print it out as it was written initially? Without the backslashes, &quot, etc

UPDATE 1

Here is how I insert/update in 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));

And even when not escaping the value, it gets inserted with a backslash before the double quotes...

  • 写回答

2条回答 默认 最新

  • dou1908 2014-12-28 18:48
    关注

    You escape the string when assigning it to $mapLink:

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

    If you want to insert it to the database as-is, simply take the value from post, and don't escape it. (Also, that's not the escaping you would use to prevent SQLi)

    To prevent SQL injection, use mysql binding like so:

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

    See more info on parameter binding in the PHP docs here.

    If you have problems with magic quotes, you can strip them like so:

    $mapLink = stripslashes($_POST['mapLink']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料