2014-10-27 157 views
-3

我還是PHP新手,我已經嘗試了幾個解決方案,但我似乎在這裏錯過了一個觀點。 我有2個警告和1個致命錯誤。我對這兩個警告更感興趣,但歡迎任何幫助。如何解決我的代碼中的include_once問題?

警告(!):include_once(型號/註冊/ register_member.php):未能打開流:C中沒有這樣的文件或目錄:行\ WAMP \ WWW \控制器\寄存器\的index.php 3

(include_path ='.; C:\ php \ pear')在C:\ wamp \ www \ controller \ register \中打開'model/register/register_member.php'失敗。致命錯誤:調用第20行的C:\ wamp \ www \ controller \ register \ index.php中的非對象的成員函數prepare()

我的5文件:(所有都在C:\ wamp \ www)

模型/註冊/ register_member.php

function register_member($pseudo, $pass_hache, $email) { 
  
    global $db; 
    $req = $db->prepare('INSERT INTO membres(pseudo, password, email, date_inscription) VALUES(:pseudo, :password, :email, CURDATE())'); 
    $req->execute(array(
        'pseudo' => $pseudo, 
     'email' => $email)); 
    $req->closeCursor(); 
        'password' => $pass_hache, 
} 

控制器/註冊/ index.php的

<?php 
  
include_once('model/register/register_member.php'); 
  
if(isset($_POST['inscription'])) { 
  
  
    // On rend inoffensif les données de l'utilisateur 
    $_POST['pseudo'] = htmlspecialchars($_POST['pseudo']); 
    $_POST['password'] = htmlspecialchars($_POST['password']); 
    $_POST['password2'] = htmlspecialchars($_POST['password2']); 
    $_POST['email'] = htmlspecialchars($_POST['email']); 
  
  
    /** 
     * Vérification si le pseudo est disponible 
     */ 
  
    global $db; 
    $req = $db->prepare('SELECT pseudo FROM membres WHERE pseudo = ?'); 
    $req->execute(array($_POST['pseudo'])); 
  
    $resultat = $req->fetch(); 
  
    if (!$resultat) { 
        $pseudo = $_POST['pseudo']; 
    } else { 
        include_once('view/register/unavaipseudo.php'); 
    } 
  
  
    /** 
     * Vérification de la validité de l'adresse mail 
     */ 
    if (isset($_POST['email'])) { 
        $_POST['email'] = htmlspecialchars($_POST['email']); // On rend inoffensives les balises HTML que le visiteur a pu rentrer 
  
        if (preg_match("#^[a-z0-9._-][email protected][a-z0-9._-]{2,}\.[a-z]{2,4}$#", $_POST['email'])) { 
            $email = $_POST['email']; 
        } else { 
            //echo 'L\'adresse ' . $_POST['mail'] . ' n\'est pas valide, recommencez !'; 
            //header('Location: mypage.php'); 
            include_once('view/register/wrongmail.php'); 
        } 
    } 
  
    /** 
     * Vérification si le mdp est correct 
     */ 
    if (!($_POST['password'] == $_POST['password2'])) 
        include_once('view/register/wrongpass.php'); 
  
    /** 
     * Hachage du mot de passe 
     */ 
    $pass_hache = sha1($_POST['password']); 
  
    $pseudo = $_POST['pseudo']; 
    $email = $_POST['email']; 
  
    register_member($pseudo, $pass_hache, $email); 
  
    echo 'Vous avez été inscrits !'; 
} 
else 
{ 
    include_once('view/register/index.php'); 
} 

視圖/註冊/ index.php的

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  
<html xmlns="http://www.w3.org/1999/xhtml"> 
  
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
        <title>Inscription</title> 
    </head> 
    <style> 
        form 
        { 
            text-align:center; 
        } 
    </style> 
       
    <body> 
        <h3>Inscrition à l'espace membre.</h3> 
  
        <form action="controller/register/index.php" method="post"> 
                <p><label for="pseudo">Pseudo :</label> <input type="text" id="pseudo" name="pseudo" /></p> 
                <p><label for="pass">Mot de passe : </label> <input type="password" id="pass" name="password" /></p> 
                <p><label for="verif_pass">Retapez votre mot de passe : </label> <input type="password" id="password2" name="password2" /></p> 
                <p><label for="email">Adresse email :</label> <input type="text" id="email" name="email" /></p> 
                   
                <input type="submit" value="Inscription" name="inscription" /> 
        </form> 
    </body> 
</html> 

register.php(根)

<?php 
  
include_once('model/connexion_ident_conn.php'); 
include_once('controller/register/index.php'); 
  
  
/*if (!isset($_GET['section']) OR $_GET['section'] == 'index') 
{ 
    include_once('controller/register/index.php'); 
}*/ 

當然並且,文件連接到DB(模型/ connexion_ident_conn.php)。 我知道我的代碼質量真的很差,我要重寫OOP中的所有內容。但我真的很感興趣,現在我失蹤了。

+2

首先,你應該設置你的自動加載機制,當一個MVC模式。 – AlexL 2014-10-27 08:48:17

+0

找到解決方案:include_once('/../../ model/register/register_member.php'); 自動加載機制是什麼意思? – Scholes18 2014-10-27 08:51:00

回答

0

您的文件是內部 controller/register/index.php

,你包括 include_once('model/register/register_member.php');

可能是你不包括從你這裏web-root文件。擁有國內領先的斜線嘗試: include_once('/model/register/register_member.php');
或者你要回去你的文件結構: include_once('/../../model/register/register_member.php');

亞歷克斯·林特的評論:

Autoload意味着每次使用類,自動包含。
就以如何實現它一看,這裏:
http://php.net/manual/en/language.oop5.autoload.php

0

你2個警告與你的路的錯誤!

所以insteat這個:

include_once('model/register/register_member.php'); 

它應該是:

include_once('/../../model/register/register_member.php'); 

而你的錯誤有待辦事項與$db變量,它是不是一個對象!