CONNECTER A SA BASE DE DONNEES

Fermé
Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016 - Modifié par crapoulou le 8/04/2016 à 23:34
Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016 - 9 avril 2016 à 19:52
Bonjour

J'ai un probleme avec ce code qui marche localement mais pas sur internet,

1-Code de connexion:
<?php
header('Content-Type: text/html; charset=UTF-8');
function connectejbardha_inscription(){
$base = mysql_connect ('localhost',"admin","ejbardha");
mysql_select_db ('ejbardha_inscription', $base) ;
mysql_query("SET NAMES 'utf8'");  
}
?>


2-Code de formulaire:
<html><head>
<link  rel="stylesheet" type="text/css" href="style11.css"/><title>Déclarer un perdus الإعلان عن ضائع</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 

</head>
<body><div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/fr_FR/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<img src="DM/accueil2.gif" align="center" border="2" width="100%" height="80"/>
 <div class ="logo"><marquee  direction="right" height="12" width="100%" ><h0>مرحبا بكم في موقع اجبار الظالة الذي  يمكنكم من الإعلان  المجاني عن كل ما ضاع عليكم  أو  ما وجدتموه  ضائعا على غيركم و تودون إيصاله إليه </marquee><marquee direction="left" height="12" width="100%"><h0> Vous etes les bienvenues dans votre site Ejbardhalla qui vous permet de déclarer gratuitement vos objets perdus ou les objets que vous avez retrouvés et que vous voulez rendre à leurs propriétaires</marquee></div><table background = "DM/livre.jpg" cellpadding="0" cellspacing="0" border="1" width="100%">
<h3><TR><h3><TD width="150" align="center"><A CLASS="menub" HREF="index.php"><font color= "noir">الرئيسية</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="contacta.php"><font color= "noir">للإتصال بنا</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF=" livreor.php"><font color= "noir">شارك برأيك</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="affich.php"><font color= "noir">الأشياء الضائعة</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="affich1.php"><font color= "noir">الأشياء المعثور عليها</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="saisit.php"><font color= "noir">الإعلان عن ضائع</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="saisit1.php"><font color= "noir">الإعلان عن معثور عليه</font></A></TD></h3></tr>

<h3><TR><h3><TD width="150" align="center"><A CLASS="lien" HREF="index.php"><font color= "noir">Accueil </font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="contact.php"><font color= "noir">Nous contacter</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="livreor.php"><font color= "noir">Participez</font></A></TD></h3>
<h3><TD width="150" align="center"><A CLASS="menub" HREF="affich.php"><font color= "noir">Objets perdus</font></A></TD></h3>
<h3><TD width="180" align="center"><A CLASS="menub" HREF="affich1.php"><font color= "noir">Objets retrouvés</font></A></TD></h3>
<h3><TD width="180" align="center"><A CLASS="menub" HREF="saisit.php"><font color= "noir">Ajouter un perdu</font></A></TD></h3> 
<h3><TD width="220" align="center"><A CLASS="menub" HREF="saisit1.php"><font color= "noir">Ajouter un retrouvé</font></A></TD></h3>
</tr></table></H2>
<div class="fb-like" data-href="[http://www.ejbardhalla.com/]" data-send="true" data-width="450" data-show-faces="true"></div> 
<font size="4" align="left" color="cfe001"><center><?php include('datte.php');?></center></font>                     
<table bgcolor="#0066FF" background= "DM/H.jpg" cellpadding="29" cellspacing="23" border="0" width="20%" heigth="20%" align="left"   bordercolor="red">            
<tr><TD width="150"><H3></body>
</html><div><marquee direction="left" height="12" width="100%" ><img src="DM/vc.jpg" align="center" width="150" height="100"/></marquee></div></TD></tr></h3> 
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="info.php"><font color= "blue">Infomations sur l'utilisation</font></A></TD></tr>
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="sitsa.php"><font color= "blue"> Sites importants </font></A></TD><h3></TR>
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="nous.php"><font color= "blue">Qui sommes nous</font></A></TD><h3></tr>
  
</table> 
<table   bgcolor="#0066FF" cellpadding="19" cellspacing="21" border = "0" width="20%" heigth="20%" align="right"   bordercolor="red" background= "DM/H.jpg">  
<tr><TD width="150"><h1><div><marquee direction="left" height="12" width="100%" ><img src="DM/vc.jpg" align="center" width="150" height="100"/></marquee></div></TD></tr></h3></TD></tr></h1>
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="infoa.php"><h4><font color= "blue">معلومات عن الإستخدام</font></A></TD><h3>
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="sitsa.php"><h4><font color= "blue"> مواقع مهمة </font></A></TD><h3></TR>
<tr><h3><TD width="150" align="center"><A CLASS="menub" HREF="nousa.php"><h4><font color= "blue">من نحن</font></A></TD><h3></tr> 
</table>
<form enctype="multipart/form-data" action="stocke.php" method="post"> 
<table border ="0" align ="center"><td>Les champs precedés par étoile 
sont obligatoires</td>
<td>   الخانات المسبوقة  بنجمة  كلها ضرورية </td></tr></table>
          <br><table width="57%" border="0"   align="center" cellpadding="6" bordercolor="red"   
      cellspacing="0"  bgcolor ="#38435C" background="">
              <tr>
                  <td width="30%">
                      <div align="right">Nom complet <font color="red"> *</font></div>
                  </td>
                  <td colspan="2">
                      <div align="left">
                      <input type="text" name="name" size="32" maxlength="50"> 
                     <font color="red"> *</font> الإسم الكامل</div>
                  </td>
              </tr>
<tr>
                  <td width="30%">
                      <div align="right">E-mail</div>
                  </td>
                  <td height="2" colspan="2">
                      <input type="text" name="email" size="32" maxlength="50">

                  البريد الإلكتروني</td>
              </tr>
              <tr>
                  <td width="30%">
                      <div align="right">Téléphone <font color="red"> *</font></div>
                  </td>
                  <td height="2" >
                   <input type="text" name="tel" size="32" maxlength="20">
                 <font color="red"> *</font> الهاتف</td>
              </tr>
              <tr>
                  <td width="30%">
                      <div align="right">L'objet perdu <font color="red"> *</font></div> 
                  </td>
                  <td height="2" >
                      <input type="text" name="objetp" size="32" maxlength="50"> 

                 <font color="red"> *</font> إسم الشيء الضائع</td>
              </tr>
<tr>     
                    
                     <td width="30%"> <div align="right">Photo </div> 
                  </td>
                  <td height="2" >
                      <input type="hidden" name="MAX_FILE_SIZE" value="100000">
                      <input type="file" name="image" size="33"> 
                   صورة</td>                            
              </tr>  
              


              <tr>
                  <td width="30%" height="57">
                      <div align="right">Description <font color="red"> *</font></div> 
                  </td>
                  <td height="57" colspan="2">
                      <textarea name="description" cols="33" rows="6"></textarea>  
                 <font color="red"> *</font> الوصف</td>
              </tr>

              <tr><td></td>
                  <td colspan="2">
                      <div align="left">
                      <input type="submit" name="Submit" value="Envoyez    إرسال">  
                      <input type="reset" name="Submit" value="Supprimez   مسح">
                      </div> 
                  </td>
              </tr>
          </table>
       <br><br>  
</form></body>
</html>
</TD></tr></h3> 

  
<?php include ("prc.php");?> <?php include('connectes.php');?>   
<center><font color ="cyan"><h6> كل الحقوق محفوظة Copyright © 2013 ejbardhalla.com</h6></font></center>
<table width ="100%" heigth="20%" border ="0" background ="DM/11.jpg"><tr><td width="100%" align ="center"></td></tr>
<tr><td width="100%" align ="center"></td></tr><tr><td width="100%" align ="center"></td></tr></table>    
</body></html>                              

</body></html> 


3-Code de stockage:
<?php
include("fonctions.php");
?><html><head> <link  rel="stylesheet" type="text/css" href="style.css"/><title>Stckage des données تخزين المعطيات</title>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/> </head>
<body bgcolor="#911ff1"><H2>
<pre><?php header('Content-Type: text/html; charset=UTF-8');
if (isset($_POST['Submit'])) { 
 $name=$_POST['name'];  
 $email=$_POST['email'];
 $tel=$_POST['tel'];   
 $objetp=$_POST['objetp']; 
 $description=$_POST['description'];          


if ( empty($name) ) {
 die("<center>Vous devez écrire votre nom-يجب أن تكتبوا إسمكم");

}
if((empty($_POST['email']))) {   
         echo $_POST['email'];   
      }

else if ( 1 < (strlen($_POST['email']) < 5) || (strlen($_POST['email']) > 60)) {                                
          die("L'adresse e-mail est trop court ou trop long-البريد إما طويل جدا أو قصير جدا");    
      }
      else if(!(preg_match("#@#",$_POST['email']))){ 
      die("L'adresse e-mail n'est pas correct, le symbole @ est absent      
            البريد غير صالح,  العلامة @ غير موجودة");   
      }
      else { 
      }  

if ( empty($tel) ) {
 die("<center>Vous devez entrer votre numéro de téléphone-يجب أن تكتبوا رقم هاتفكم");
}
if ( empty($objetp) ) {
 die("<center>vous devez écrire le nom d'objet perdu-يجب أن تكتبوا إسم الشيئ الضائع");
}
if ( empty($description)) {
 die("<center>Vous devez décrir l'objet perdu-يجب وصف الشيئ الضائع");  
}


// *************************

if(empty($_POST['name'])) {
        die("Vous devez écrire votre nom-يجب أن تكتبوا إسمكم");  
     }
elseif ( (strlen($_POST['name']) < 3) || (strlen($_POST['name']) > 40)) {                  
        die("Le nom incorrect-الإسم غير صالح");
     }
else {
        
      }

if(empty($_POST['tel'])) {
          die("Vous devez entrer votre numéro de téléphone-يجب أن تكتبوا رقم هاتفكم");
      }
      elseif ((strlen($_POST['tel']) < 8) || (strlen($_POST['tel']) > 20)) {  
          die("Numéro de téléphone trop court ou trop long-رقم الهاتف إما طويل جدا أو قصير جدا");
      }
      
else { 
          }             

      
if(empty($_POST['objetp'])) {
          die("Vous devez ecrire le nom d'objet perdu-يجب أن تكتبوا إسم الشيئ الضائع");  
      }

elseif ((strlen($_POST['objetp']) < 3) || (strlen($_POST['objetp']) > 25)) {  
          die("Nom d'objet trop court ou trop long-إسم الشيئ الضائع طويل جدا أو قصير جدا");
      }
      else {   
      }

 
 
           

if(empty($_POST['description'])) {
          die("Vous devez décrire l'objet perdu-يجب وصف الشيئ الضائع");
      }
elseif ( (strlen($_POST['description']) < 5) || (strlen($_POST['description']) > 400)) {
          die("La description est trop courte ou trop longe-الوصف إما طويل جدا أو قصير جدا"); 
      }
else {
           
      }
     
$dossier = './imagesp/';
$fichier = basename($_FILES['image']['name']);
$taille_maxi = 1000000; 
$taille = filesize($_FILES['image']['tmp_name']);
$extensions = array('.png', '.gif', '.jpg', '.jpeg','.bmp');
$extension = strrchr($_FILES['image']['name'], '.');   
//Début des vérifications de sécurité... 
if(empty($fichier)){ $fichier="pas-d'imagep.jpg";} 
else {          
if(!in_array($extension, $extensions)) //Si l'extension n'est pas dans le tableau  
{   
 die ("Vous devez uploader seulement une image de type: png, gif, jpg, jpeg ou bmp.          
 .bmp أو jpeg ,jpg ,gif ,png :ينبغي أن تكون الصورة المرفقة فقط من النوع  
 ");                                                        
} 

if($taille>$taille_maxi)      
{    
     die ("Le fichier est trop gros...الصورة كبيرة الحجم");              
}

if(!isset($erreur)) //S'il n'y a pas d'erreur, on upload          
{ 


     //On formate le nom du fichier ici...    
     $fichier = strtr($fichier,
         'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
         'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
     $fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);  
     if(move_uploaded_file($_FILES['image']['tmp_name'], $dossier . $fichier)) //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
     {   }   

 else //Sinon (la fonction renvoie FALSE).      
     {   
         die ("Echec de téléchargement de photo ! هناك خطأ في تحميل الصورة"); 
                     
     }
} 

}   


connectejbardha_inscription(); 
if(empty($fichier)){ $fichier="pas-d'imagep.jpg";}   
 
date_default_timezone_set("UTC");
$date  = date("Y/m/d");


//Obtention de l'ID en incrmentant d'une unit
// le dernier ID cr.
$query="select MAX(id) as id from objet_perdu";
$result=mysql_query($query);
if($row=mysql_fetch_array($result)) {
 $id = ++$row[0];
}
else {
 die("problme lié à l'id!");       
} 

       
$query="INSERT into objet_perdu VALUES('".mysql_real_escape_string(stripslashes($id))."','".mysql_real_escape_string(stripslashes($name))."','".mysql_real_escape_string(stripslashes($email))."','".mysql_real_escape_string(stripslashes($tel))."','".mysql_real_escape_string(stripslashes($objetp))."','".mysql_real_escape_string(stripslashes($fichier))."','".mysql_real_escape_string(stripslashes($description))."','".mysql_real_escape_string(stripslashes($date))."')";  
$result=mysql_query($query);
if (!($result)) {
 die(" Il y a erreur هناك خطئ ما");                                                                                                               
}}

 //Affichage en retour des donnes enregistres. 

?> <table align= "center" border ="0" width= "100%" height= "79%"> 
<?php   
echo "  <tr><td align=center><font color= cyan > <h2><B>Merci, vos données sont conservées : شكرا , لقد تم حفظ معطياتكم</B></h2></font>","</td></tr>";                                                
echo "  <tr><td align=center><u><font color= cyan ><h2><B> Vous   أنتم </h2></B></u></font></tr></td>";  
echo "  <tr><td align=center><h3><B>",$name," // ",$email," //  ",$tel,"</h3></B></tr></td>" ; 
echo "  <tr><td align=center><u><font color= cyan ><h2><B>L'objet perdu  الشيء الضائع</h2></B></u></font></tr></td>";             
echo "  <tr><td align=center><h3><B>",$objetp,"</h3></B></tr></td>";
echo "  <tr><td align=center><h3><B>",$fichier,"</h3></B></tr></td>"; 
echo "  <tr><td align=center><h3><B>",$description,"</h3></B></tr></td>";          
echo "  <tr><td align=center><h3><B>",$date,"</h3></B></tr></td>";    
?>
</table>
<h3><A CLASS="menub" HREF="index.php"><center><b>Accueil-الرئيسية</center></b></A></h3>
<?phpinclude ("prc.php"); ?>
</body></html>


Et voici la BD:
-- phpMyAdmin SQL Dump
-- version 3.3.9
-- https://www.phpmyadmin.net/
--
-- Host: localhost
-- Generation Time: Apr 05, 2016 at 01:59 PM
-- Server version: 5.5.8
-- PHP Version: 5.3.5

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Database: `ejbardha_inscription`
--

-- --------------------------------------------------------

--
-- Table structure for table `objet_perdu`
--

CREATE TABLE IF NOT EXISTS `objet_perdu` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Nom` varchar(50) NOT NULL,
`E-mail` varchar(50) DEFAULT NULL,
`Tel` int(50) NOT NULL,
`Objetp` varchar(50) NOT NULL,
`image_src` varchar(150) DEFAULT NULL,
`Description` text NOT NULL,
`date_inscrit` date NOT NULL,
UNIQUE KEY `id` (`id`),
KEY `Objetp` (`Objetp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `objet_perdu`
--


-- --------------------------------------------------------

--
-- Table structure for table `objet_trouve`
--

CREATE TABLE IF NOT EXISTS `objet_trouve` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`Nom` varchar(50) CHARACTER SET utf8 NOT NULL,
`E-mail` varchar(50) CHARACTER SET utf8 DEFAULT NULL,
`Tel` int(50) NOT NULL,
`Objett` varchar(50) CHARACTER SET utf8 NOT NULL,
`image_src` varchar(150) DEFAULT NULL,
`Description` varchar(400) CHARACTER SET utf8 NOT NULL,
`date_inscritt` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `Objett` (`Objett`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

--
-- Dumping data for table `objet_trouve`
--



Excusez moi je vous ai montrer tout pour que ca soit claire.
NB: la question est pourquoi je ne peux pas connecter à ma BD?

1 réponse

Regis59 Messages postés 21143 Date d'inscription mardi 27 juin 2006 Statut Contributeur sécurité Dernière intervention 22 juin 2016 1 320
9 avril 2016 à 01:34
Salut,

Donc tu veux héberger un site chez un hébergeur et utiliser une base de données locale??
Ton hébergeur te fournir une BDD?
0
Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016 2
9 avril 2016 à 02:22
Bonjour
Merci pour l'aide, j'ai pris une espace sur un serveur et ce n'est pas la premier fois que j'heberge un site, j'ai tout fait pour connecter à ma BD mais!!!!!.
0
Regis59 Messages postés 21143 Date d'inscription mardi 27 juin 2006 Statut Contributeur sécurité Dernière intervention 22 juin 2016 1 320 > Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016
9 avril 2016 à 11:59
$base = mysql_connect ('localhost',"admin","ejbardha");
mysql_select_db ('ejbardha_inscription', $base) ;


par:

$base = new PDO('mysql:host=localhost;dbname=ejbardha_inscription', 'admin', 'ejbardha');


Et sous cette forme?
0
Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016 2
9 avril 2016 à 17:29
Bonjour
J'ai fait ce que vous m'avez demandé et voici le message d'erreur :


Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[28000] [1045] Access denied for user 'admin'@'localhost' (using password: YES)' in /home/ejbardha/public_html/fonctions.php:4
Stack trace:
#0 /home/ejbardha/public_html/fonctions.php(4): PDO->__construct('mysql:host=loca...', 'admin', 'ejbardha')
#1 /home/ejbardha/public_html/stocke.php(134): connectejbardha_inscription()
#2 {main}
thrown in /home/ejbardha/public_html/fonctions.php on line 4
0
Regis59 Messages postés 21143 Date d'inscription mardi 27 juin 2006 Statut Contributeur sécurité Dernière intervention 22 juin 2016 1 320
Modifié par Regis59 le 9/04/2016 à 18:49
    Le mot de passe entré n'est pas le bon.


Aucun mot de passe n'a été donné alors que le serveur en attend un (option -p du client MySQL en ligne de commande par exemple). Voir également cette question


L'utilisateur n'a pas les droits pour se connecter ou sur certaines tables. Pour voir les droits d'un utilisateur, utilisez la commande SHOW GRANTS FOR user@host. Si nécessaire, donnez les privilèges au user (voir plus haut). N'oubliez pas de faire un FLUSH PRIVILEGES pour recharger les droits (voir également cette question).


L'utilisateur est occulté par un autre plus prioritaire mais aux droits plus restreints. Le serveur MySQL considère d'abord les users les plus spécifiques (avec une adresse IP précise ou « localhost » par exemple) avant de prendre en compte les plus génériques (caractères '%' ou '_' dans le nom du user ou de l'hôte). Voir également cette question

Ex : si l'utilisateur Bob se connecte à partir de la machine locale où se trouve le serveur MySQL, les droits de 'bob@localhost' primeront, s'ils existent, sur les droits de 'bob@%'.

Les erreurs d'accès s'expliquent souvent par la présence d'utilisateurs anonymes (user='') dans la table users qui masquent les droits de certains autres utilisateurs. Pour y remédier, on peut les supprimer par un DELETE FROM mysql.user WHERE user=''.


Tout le détail ici: https://mysql.developpez.com/faq/?page=Erreurs-de-connexion#Access-denied-for-user-xx-xx-using-password-Y-N
0
Ennemine Messages postés 67 Date d'inscription mercredi 6 novembre 2013 Statut Membre Dernière intervention 11 juillet 2016 2
9 avril 2016 à 19:52
pourquoi ça marche à locale alors???
0