<?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "database name"; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?>Now that the connection to our database is established we will insert our encoded creative in a table. Encode.php
<?php if(isset($_POST['submit'])) { require('connection.php'); $test=$_POST['html']; $encode= urlencode($test); $sql = "INSERT INTO `creative` (`encode`) VALUES ('$encode');"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); } ?> <!DOCTYPE html> <html> <head> <title>Title of the document</title> </head> <body> <form method="post" action="#"> <input type="text" name="csyntax" placeholder="csyntax"><br> <input type="text" name="vsyntax" placeholder="vsyntax"><br> <textarea name="html" cols="50" rows="50"> </textarea> <br> <input type="submit" name="submit"> </form> </body> </html>Then we will fetch the stored string from the database the string will be in encoded format to decode this string we will make use of urldecode () function. The urldecode() function will return our html content which was stored in the database in encoded format. For fetching our html content which is stored in encoded format we will use select command and we will decode it using urldecode() function Decode.php
<?php require('connection.php')'; $sql = "SELECT * FROM creative"; $result = mysqli_query($conn, $sql); $row = mysqli_fetch_assoc($result); $encodeurl=$row['encode']; $decodeurl=urldecode ($encodeurl); echo $decodeurl; mysqli_close($conn); ?>