L'insertion de données ne marche pas dans cpanel,aidez-moi

Fermé
Dav - 12 févr. 2023 à 19:29
 Dav - 12 févr. 2023 à 22:56

Bonjour, en local l'insertion de données se fait mais enligne cela ne marche pas besoin d'aide svp


Windows / Edge 109.0.1518.78

<?php 
session_start();
$db= new PDO('mysql:host=localhost;dbname=databasename','username', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


 
if(isset($_POST['btnsignup'])){
   

    $prenom=htmlspecialchars($_POST['prenom']);

    $tel=htmlspecialchars($_POST['tel']);
   
    
    $mdp=sha1($_POST['mdp']);
    // $mdplength=strlen($mdp);
 
    if(!empty($prenom) and !empty($tel)  and !empty($mdp)){

    if (isset($_FILES['avatar']) AND !empty($_FILES['avatar']['name'])) {
        $tailleMax=203715200;
        $extensionsValides=array('jpg','jpeg','gif','png');
        if ($_FILES['avatar']['size']<=$tailleMax) {
            $upload=strtolower(substr(strrchr($_FILES['avatar']['name'], '.'), 1));
            if(in_array($upload, $extensionsValides)){
                $chemin="/home/vitachat/public_html/avatars/".$avatar;
                $resultat=move_uploaded_file($_FILES['avatar']['tmp_name'], $chemin);
                if($resultat){


         $insertuser=$db->prepare("INSERT INTO `user`(`prenom`,`tel`,`pass`,`avatar`) VALUES(?,?,?,?)");
         $insertuser->execute(array(
        $prenom,
        $tel,
    
        $mdp,
        $avatar
       ));


         header('Location:index.php?');


}

     
        
    }
    else{
        $msg="Fill out all fields,try again please";
    }

}
}
}
else{
        $msg="Fill out all fields,try again please";
    }

}


?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
     <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="signup.css">
    <title>Vitachat</title>
</head>
<body>

        <section class="form signup">
            <header style="font-size: 30px;
">
                Vitachat
            </header>
            <br>

            <form action="" method="post" enctype="multipart/form-data">
                <?php if(isset($msg)){ 
                    ?>
                <div align="center" class="error-txt" style="background-color: white;color:red;border: 1px solid blue;border-radius: 5px; font-size: 20px;width: 67vw;margin-top: -5px;">
                    <?php echo $msg; ?></div>
                <br>
                
                <?php 

            }
        ?>
                <div>
                    <div  align="left" style="position:relative;">
                      <strong>
                    <div style="margin-left: 5px;">
                    <i class="fa fa-camera" style="position:absolute;margin-top: 10px;margin-right: 350px;margin-top:-2 px;margin-left: 8px;color: white;border:;"></i>
                      
              <input onchange="previewPicture(this)" type="file" accept="image/*" name="avatar" style="border-color:white;outline: none;position: absolute;width: 22px;margin-top: 5px;margin-left: 5px;opacity: 0;">
</div>
          
          <img  id="image" style="width: 100px; margin-top: -20px;border-radius: 50%;height: 100px;margin-left: -25px;border: 0px solid white;background-color: blue;" >


                    </div>

<br>
                    <div id="field" class="field input">
                       
                        <input type="text" id="input" class="first" name="prenom" placeholder="First Name">
                    </div>
<br>
                    <div id="field" class="field input">
                        
                        <input type="tel" id="input" name="tel" placeholder="Tel">
                    </div>

                    <br>


                    <div id="field" class="field input">
                        
                        <input type="password" name="mdp" id="input" placeholder="Password">
                        <i id="eye" style="color:red;margin-left: px;position: ;" class="fa fa-eye"></i>

                     
                    
                        
             


                    </div>
<br>
                    <div class="field input">
                        
                        <input  type="submit" class="signups" value="Sign Up" name="btnsignup" style="background-color: white;color: blue;cursor: pointer;border:1px solid blue;width: 70vw;">
                    </div>

                </div>
            </form>

            <div class="link" align="center">Already signed up?

<br>
                <button class="click" style="background-color: white;color: blue;cursor: pointer;border:1px solid blue;"><a class="click" href="index.php" style="color:blue;background-color: white;text-decoration: none;font-size: 20px;">

                Log In</a></button></div>
        </section>
   

   
</body>
</html>

A voir également:

2 réponses

jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 4 650
12 févr. 2023 à 22:45

Bonjour,

Commence par appliquer ceci : https://forums.commentcamarche.net/forum/affich-37584941-php-pdo-gerer-les-erreurs

(pense à retirer les redirection (header("location..  ) le temps des tests.. sinon tu ne verras pas les éventuelles erreurs.

Et vérifies également les identifiants que tu as utilisé pour la connexion à ta base de données.

En ligne, il est rare que le host soit localhost


0

MERCI BEAUCOUP je vais l'essayer vous dire la suite

0