2014-10-27 36 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变量,它是不是一个对象!