发送特殊字符到db sql

时间:2017-06-09 21:32:33

标签: php html sql

我在我的数据库中添加了一个数据库表调用google_analytics,并在我的管理区域添加了一个表单。这是我在下面使用的代码。我用它来存储Google Analytics网络跟踪代码。

    //GOOGLE ANALYTICS EMBED

                if(isset($_POST['google_analytics_id'])){
                    extract($_POST);

 $sql = "UPDATE google_analytics SET 
  google_analytics_id='$google_analytics_id' WHERE id=1";
    if ($con->query($sql) === TRUE) {
    header('location:setting.php?msg=102');

} else {
     echo "Error updating record: " . $conn->error;
 }
                }
?>   




    //FORM FOR SUBMITTING   


  <div class="panel panel-primary">
  <div class="panel-heading">Google Analytics Embed </div>
  <div class="panel-body">
  <?php
  $qry="select * from google_analytics";
                $result=mysqli_query($con,$qry) or die(mysqli_error($con));?>



                        <?php  
                        if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
    $google_analytics_id = $row["google_analytics_id"]; 

   }
}

  ?>

  <form method="post" action="">

                <form  class="form-horizontal" method="post" enctype='multipart/form-data' >                       

                    <div style="clear:both; height:15px;"></div>
                    <div id="popup_bg_container" class="form-group required">
                        <label for="google_analytics_id" class="control-label col-md-4  requiredField">Google Embed Code<span class="asteriskField">*</span> </label>
                        <div class="controls col-md-8 ">
                        <textarea  class="input-md  textinput textInput form-control" id="google_analytics_id" maxlength="1000" name="google_analytics_id" style="margin-bottom: 10px; min-height:200px;" type="text"  value="<?php echo $google_analytics_id; ?>"><?php echo $google_analytics_id; ?></textarea>

                        </div>

                    <div id="submit" class="form-group required">
                        <div class="controls col-md-12" style="text-align:right;">
                            <button type="submit" class="btn btn-primary right" name="submit" value="submit now">Save</button>
                        </div>
                    </div>


                </form>

            </form>
  </div>
  </div>

所以我想将以下信息发送到我的数据库。

 <script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new 
  Date();a=s.createElement(o),
   m=s.getElementsByTagName(o)
 [0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-
 analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxxx-1', 'auto');
   ga('send', 'pageview');

 </script>

`

所以问题是我可以向数据库发送字母数字信息,但它不会保存特殊字符。比较''如何编辑上面的代码以将特殊字符保存到数据库中。

由于

0 个答案:

没有答案