How to insert and display an url link in a MYSQL database with PHP

How to insert and display an url link in a MYSQL database with PHP

Download the Mobile application:


To insert an URL link into a MySQL database, just enter the string STRING. Before inserting it into the base
Example:

$url = "test";
$url= base64_encode($url);

Now, once inserted, you need to DECODER it so that it can be displayed correctly:
$ Decode = base64_decode ($ url);

Finally add it in an HREF tag:
<a href='$decode'>URL</a>

Step 1: Create a given database:

CREATE DATABASE pacific;
use pacific;
 create table pacific (int id (10) NOT NULL AUTO_INCREMENT PRIMARY KEY, name varchar (100) not null, description varchar (255) not null, double price, url varchar (255));
 alter table pacific add email varchar (25) NOT NULL;

Step 2: Once your database is created now here is the Code to insert the data into the database. Copy and paste the code below into notepad ++ or other code editor. Give him the INSERT.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>


  <link rel="stylesheet" href="css/style.css"/>
 <meta charset="utf-8" >
 
  <script type="text/javascript" src="date.js"></script>
  </head>
<body >
   
              
 
                                 <fieldset>
         <legend> <h2>Ajouter</h2> </legend>
                                          
                             <form method="post" Action="ajouterpa.php" class="rt">
        <table>

             <tr>
            <th>Nom<th>
            <td><input type="text" name="nom" size="25"placeholder="exemple: Fruit" required /> </td>
          </tr>
         
          <tr>
            <th>Description<th>
            <td><input type="text" name="description" size="25"placeholder="Exemple: Mango"  required/>  </td>
          </tr>
         
           <tr>
            <th>Prix<th>
            <td><input type="number" name="prix" size="25"placeholder="Exemple: 500"  required/>  </td>
          </tr>
         
          <tr>
            <th>URL<th>
            <td><input type="text" name="url" size="25"placeholder="Exemple: url"  required/>  </td>
          </tr>
         
            <tr>
            <th>Email<th>
            <td><input type="text" name="email" size="25"placeholder="Exemple: jbej90@gmail.com"  required/>  </td>
          </tr>


       </table>
       <table>
              

                                               </form>
           
                          <input type="submit" name="save" value="save" />
              <input type="reset" name="reset"  />



 
                                             
         
                                </fieldset>
        

 
 </body>
 <?php
$con=@mysql_connect("localhost","root","");
if(!$con){
die('Erreur de connection' .mysql_error());
}
/*
create database formulaire;
 use formulaire;
create table forme(prenom varchar(20),nom varchar(20), adresse char(20),
email char(20), tel char(20), commentaire char(100) );  */
$url='';
@mysql_select_db('pacific',$con);
 if(isset($_POST ['nom']) && isset($_POST['description']) && isset($_POST['prix']) && isset($_POST['url']) && isset($_POST['email']) ){

$nom = $_POST['nom'];
$description = $_POST['description'];
$prix = $_POST['prix'];
$email = $_POST['email'];
$url = $_POST['url'];
$url= base64_encode($url);   // base64_encode et base64_decode vous permet d'ajouter un lien dans une base de donnee mysql et de faire appaire ce lien pour l'afficher dans une autre page
//$url= mysql_real_escape_string($url);

$sql=" insert into pacific SET nom='$nom', description= '$description' , prix='$prix' , url='$url' , email='$email'; " ;
@mysql_query($sql) ;
        //on ferme la connexion a la base
       
        @mysql_close();
echo"<html> <font color=green> <center> [ Mr/Mrs: ]  Vos Informations sont stockées !!!  </center> </font> <html>";
}
else{
 die('<html> <font color=red>Erreur SQL, Les champs sont peut etre vide!'.'<br /> </font></html>'.@mysql_error()); // rammemne l'erreurr
}
?> 



    </html>

 
Step 3: Now you can view the data entering the database as well as the URL link of the page you want to open. Copy and paste this code into your editor give it the name: SHOW.php
<?php
//connection au Serveur
@mysql_connect("localhost","root","") or die(mysql_error());  //@mysql_connect("mysql.hostinger.fr","u884364132_rene","superhind2015") or die(mysql_error());
//connection a la base
@mysql_select_db('pacific')or die(mysql_error());
//String variable
$output='';
//collect
if(isset ($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
// requete de selection
$query= @mysql_query("Select * from pacific where nom like'%$searchq%' or description like'%$searchq%' or prix like'%$searchq%' or email like'%$searchq%' ") or die('could not search!');
//conteur
$count= @mysql_num_rows($query);
//si la recherche est vibe:
if($count == 0){
$output='no search results !';
}
if(empty ($_POST['search'])){
$output='La case est vide!';
}
else{
while($row = mysql_fetch_array($query)){
$fname= $row['nom'];
$lname=$row['description'];
$mname=$row['prix'];
$email=$row['email'];
$link=$row['url'];
$decode=base64_decode($link);
$output .='<div> ' .$fname.' '.$lname.' '.$mname.' '.$email.'</div>';
$output .='<div> <a href='.$decode.' target="_blank">url</a>  </div>';
$output .='<div> '.'<HTML>  <font size=3 color=red>'.$searchq.' <hr/></font></div>';
}
}
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>


  <title>Search Engine||ConsHt</title>
   <meta charset="utf-8" >
   <link rel="stylesheet" href="css/search.css" type="text/css">
 
   </head>
  
  
       <body >
                       <h2>Moteur de Recherche</h2>
                    <form action='search2pacific.php'  method='post' >
                    
                    <input type='text' name='search' placeholder="Tapez un sigle.ex:PNH" size='50' >
                    <input type='image' src="img/mama.png" value='Search' width='30' height='30' /><br/>

                   </form>
       <!--Affiche le resultat dans la base-->
             <?php print("$output");?>
       <!--***********************************-->
      
       <a href="http://ddroid509.esy.es/">  <font size=2 color=BLUE>  Home page</a> <br/> <br/>
        <a href="#">  <font size=2 color=BLUE>Buy Complete SQL DATABASE for 5$\Acheter Base de donnée SQL complete pour 250gdes avec(MONCASH DIGICEL)</a>
      
                  
    </body>
</html>


Download the Mobile application:

Hey, did you like my tutorial article? do not forget to follow me on Youtube by clicking on this link:

Do not forget to follow me on my Haitian Geek Junior Facebook page by clicking here:

Download the Mobile application:

HEY, learn how to make money online with(Youtube, facebook, Playstore plus your website). Download this app we explain everything. Clic here:



Commentaires

Posts les plus consultés de ce blog

Men kijan pou voye MINUT NATCOM-NATCOM pou ZANMIW an 3 etap

Comment partager des minutes sur natcom

Men kijan pou prete kob, minutes, lajan nan men NATCOM Ayiti