2016-06-05 5 views
-1

Ich versuche für Benutzeranmeldung und Anmeldeformulare in Android. Von den letzten 5 Tagen versuche ich es. Ich kann es nicht bekommen. Kann mir bitte jemand helfen? Das ist mein Code user_control.php. Ich schließe die connection.php in user_control.php ein.Ich bekomme Syntaxfehler, unerwartete 'Header' (T_STRING) in http: // localhost: 80/opt/lampp/htdocs/user_control.php

<? php 

    class user { 
    private $db; 
    private $connection; 
    /* The below one is the consttructor*/ 
    function __construct() { 
     header('Content-Type: application/json'); /* used for including json format*/ 
     require_once 'connection.php'; 
     $this->db = new DB_Connection(); 
     $this->connection = $this->db->get_connection(); 
    } 

    public function does_user_exist($email,$password) { 
     $query = "Select * from userss where email ='$email' and password = '$password'"; 
     $result = mysqli_query($this->connection,$query); 
     if(mysqli_num_rows($result) > 0){ 
      $json['success'] = 'welcome'.$email; 
      echo json_encode($json); 
      mysqli_close($this->connection); 
     } else { 
      $query = " Insert into userss(email,password) values ('$email','$password')"; 
      $is_inserted = mysqli_query($this->connection, $query); 
      if($is_inserted == 1) { 
       $json['success'] = 'Account created, welcome '.$email; 
      } else { 
       $json['error'] = 'Wrong password'; 
      } 

      echo json_encode($json); 
      mysqli_close($this->connection); 
     } 
    } 
} 

    $user = new user(); 
    if(isset($_POST['email'],$_POST['password'])) { 
    $email = $_POST['email']; 
    $password = $_POST['password']; 
    if(!empty($email) && !empty($password)) { 
     $encrypted_password = md5($password); 
     $user -> does_user_exist($email,$encrypted_password); 
    } else { 
     echo json_encode("You must fill both fields"); 

    } 
    } 

Während ich mit Postbote Software von Chrome leite ich erhalte den Fehler als ich Syntaxfehler bin immer:

unexpected 'header' (T_STRING) in http://localhost:80/opt/lampp/htdocs/user_control.php 
+0

' Ekin

Antwort

0

Entfernen Sie den Platz in Ihrer Linie 1. Sieht so aus:

<?php 
-1

Versuchen zu Kommentar:

//header('Content-Type: application/json'); /* used for including json format*/ 

Quelle: https://stackoverflow.com/a/20620606/2381906

+0

Ich habe es getan. Aber jetzt bekomme ich Parse-Fehler: Syntaxfehler, unerwartete "Klasse" (T_CLASS) in /opt/lampp/htdocs/dir/user_control.php in Zeile 5 –

+0

Entfernen Sie den Abstand zwischen "

+0

@ NéstorLim Wenn Sie eine * neue * Antwort haben, antworten Sie auf den Post * neu *. – Biffen