I'm making a WordPress Advertisement Management Plugin. Need the user to enter Google AdSense and other ad code into the database.
I checked the other solution like the
and
&
. But they are not doing the desired result.
I'm using a simple form like <a href="https://wordpress.stackexchange.com/a/108351/22728">this</a>:
To insert into the db:
With the aforementioned code, I tried with:
and
and
The first two attempt completely failed me. But using only the
is doing a good job encoding the texts into code and inserting into the db, but when I'm trying with
in my db query, it's not showing anything.
Instead of JavaScript, I tried with simple string like "This is the code", it's doing just fine. But I failed with JavaScript code.
My google adsense code is like this:
How can I proceed then? Any ideas?
I checked the other solution like the
Code:
mysql_real_escape_string()
Code:
base64_encode()
Code:
base64_decode()
I'm using a simple form like <a href="https://wordpress.stackexchange.com/a/108351/22728">this</a>:
Code:
<form action="" enctype="multipart/form-data" method="post">
<textarea name="ad_code"></textarea>
<input type="submit">
</form>
To insert into the db:
Code:
<?php
if (!empty($_POST)) {
global $wpdb;
$table = $wpdb->my_table = $wpdb->prefix . "my_table";
$data = array(
'ad_code' => $_POST['ad_code']
);
$format = array(
'%s'
);
$success=$wpdb->insert( $table, $data, $format );
if($success) echo 'data saved';
}
?>
With the aforementioned code, I tried with:
Code:
$data = array(
'ad_code' => mysql_real_escape_string( $_POST['ad_code'] )
);
and
Code:
$data = array(
'ad_code' => base64_encode( mysql_real_escape_string( $_POST['ad_code'] ) )
);
and
Code:
$data = array(
'ad_code' => base64_encode( $_POST['ad_code'] )
);
The first two attempt completely failed me. But using only the
Code:
base64_encode()
Code:
<?php echo "<pre>" . base64_decode( $the_ad_query->ad_code ) . "</pre>"; ?>
Instead of JavaScript, I tried with simple string like "This is the code", it's doing just fine. But I failed with JavaScript code.
My google adsense code is like this:
Code:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- my ad -->
<ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-32131313131312317"
data-ad-slot="8657754785"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
How can I proceed then? Any ideas?