Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
parse error: syntax error, unexpected end of file in c:\wamp\www\form\biodata.php="" on="" line="" 115


What I have tried:

PHP
  1  <?php
  2      // connexion à la base de données
  3     $db_username = 'root';
  4      $db_password = '';
  5      $db_name     = 'licence';
  6      $db_host     = 'localhost';
  7   $cnx = mysqli_connect($db_host, $db_username, $db_password, $db_name) or die('could not connect to database');
  8  
  9   if($cnx == false){
 10      die("ERREUR : Impossible de se connecter. " . mysqli_connect_error());
 11  }
 12        // récupérertous les utilisateur
 13   ?>
 14  
 15  <!DOCTYPE html>
 16  <html lang="fr">
 17  <head>
 18      <meta charset="utf-8">
 19      <title>Mini Blog</title>
 20      <link rel="stylesheet" type="text/css" href="../css/styles.css">
 21      <meta name="viewport" content="width=device-width, initial-scale=1.0">
 22  </head>
 23  <body>   
 24       <?php 
 25  $cnx = "mysql:host=$db_host;dbname=$db_name"; 
 26    $sql = "SELECT * FROM etudiants";
 27     
 28    try{
 29     $pdo = new PDO($cnx, $db_username, $db_password);
 30     $stmt = $pdo->query($sql);
 31     
 32     if($stmt === false){
 33      die("Erreur");
 34     }
 35     
 36    }catch (PDOException $e){
 37      echo $e->getMessage();
 38    }
 39       while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : 
 40        ?>
 41  
 42       
 43      <?php
 44   
 45      //connection au serveur
 46   // $cnx = @mysql_connect( "localhost", "root", "" ) ;
 47   
 48    //sélection de la base de données:
 49  //  $db  = mysql_select_db( "licence" ) ;
 50   
 51    //récupération des valeurs des champs:
 52    $id     = $_POST["id"] ;
 53    //nom:
 54    $nom     = $_POST["nom"] ;
 55    //prenom:
 56    $prenom = $_POST["prenom"] ;
 57    //adresse:
 58    $adresse = $_POST["adresse"] ;
 59    //code postal:
 60    $mail        = $_POST["mail"] ;
 61    //numéro de téléphone:
 62    $tel       = $_POST["telephone"] ;
 63   
 64    //création de la requête SQL:
 65   // $sql = "INSERT  INTO etudiants (nom, prenom, adresse, mail, telephone)
 66    //          VALUES ( '$nom', '$prenom', '$adresse', '$mail', '$tel') " ;
 67   
 68    //exécution de la requête SQL:
 69    $requete = mysql_query($sql, $cnx) or die( mysql_error() ) ;
 70   
 71    //affichage des résultats, pour savoir si l'insertion a marchée:
 72    if($requete)
 73  
 74  {
 75    
 76  	$message = 'Etudiant enregistré dans la BD';
 77  
 78  }
 79  
 80  else {
 81  	
 82  	$message = 'Echec d ajout ';
 83  	
 84  	}
 85  	
 86      ?>
 87          <table>
 88              <tbody>
 89                <thead>
 90                  <tr>
 91  	                
 92                      <th>nom</th>
 93                      <th>prenom</th>
 94                      <th>adresse</th>
 95                      <th>mail</th>
 96                      <th>tel</th>               
 97                  </tr>
 98                </thead>
 99   
100              <tr>
101  			    <td><?php echo $article['id'];?></td>
102                  <td><?php echo $article['nom'];?></td>
103                  <td><?php echo $article['prenom'];?></td>
104                  <td><?php echo $article['adresse'];?></td>
105                  <td><?php echo $article['mail'];?></td>
106                  <td><?php echo $article['telephone'];?></td>
107                  
108                  
109              </tr>
110              
111              </tbody>
112          </table>
113          
114  </body>
115  </html>
Posted
Updated 16-Mar-21 23:22pm
v3
Comments
Peter_in_2780 16-Mar-21 20:48pm    
"Unexpected end of file" is almost always a missing delimiter, usually }
You do use a syntax highlighting editor, right?
Check that every { has a matching } IN A PHP CONTEXT
and that every <?php has a ?>

1 solution

The while statement on line 39 does not look correct:
PHP
      while($row = $stmt->fetch(PDO::FETCH_ASSOC)) : 
​
 
Share this answer
 
Comments
Babacar Diallo 17-Mar-21 9:17am    
what do you think is correct ? I always have the same error : "Parse error: syntax error, unexpected end of file in C:\wamp\www\form\admin.php on line 112"
Richard MacCutchan 17-Mar-21 9:29am    
That while statement is incorrect; what is it supposed to be there for?
Babacar Diallo 17-Mar-21 10:04am    
this is a code that I copied somewhere, instead I should put what? for info I am very new to php
Richard MacCutchan 17-Mar-21 10:19am    
Then throw this code away, and go to PHP Tutorial[^] and learn the language properly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900