2012-07-17 167 views
-2

我想通过使用xampp在php中制作注册页面,但我遇到了问题。当我运行我的PHP文件,它提供了以下错误:php注册系统错误

Notice: Undefined index: UserName in C:\xampp\htdocs\register.php on line 3

Notice: Undefined index: UserSurname in C:\xampp\htdocs\register.php on line 4

Notice: Undefined index: UserMail in C:\xampp\htdocs\register.php on line 5

Notice: Undefined index: UserPassword in C:\xampp\htdocs\register.php on line 6

Notice: Undefined index: UserTel in C:\xampp\htdocs\register.php on line 7

Warning: require(class.phpmailer.php) [function.require]: failed to open stream: No such file or directory in C:\xampp\htdocs\register.php on line 24

Fatal error: require() [function.require]: Failed opening required 'class.phpmailer.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\register.php on line 24

我的PHP文件,register.php:

<?php 
$username=$_POST['UserName']; 
$usersurname=$_POST['UserSurname']; 
$usermail=$_POST['UserMail']; 
$userpass=$_POST['UserPassword']; 
$usertelephone=$_POST['UserTel']; 
    $con = mysql_connect("localhost","root","rockenpeace"); 
if (!$con) 
{ 
    die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db("dbe", $con); 

mysql_query("INSERT INTO user (UserName,UserSurname,UserMail, UserPassword, UserTel) 
     VALUES('$username','$usersurname','$usermail','$userpass','$usertelephone')"); 

mysql_close($con); 

try 
{ 
    require("class.phpmailer.php"); 
    $mail = new PHPMailer(); 
    $mail->IsSMTP(); 
    $mail->Mailer = "smtp"; 
    $mail->Host = "ssl://smtp.gmail.com"; 
    $mail->Port = 465; 
    $mail->SMTPAuth = true; 
    $mail->CharSet="utf-8"; 
    $mail->Username = "[email protected]"; 
    $mail->Password = "password"; 
    $mail->From  = "[email protected]"; 
    $mail->FromName="DBE Yazılım"; 
    $mail->AddAddress($_POST['usermail']); 
    $mail->Subject = "Registration Information"; 
    $mail->Body  = "Hello your password is " . $userpass; 
    //$mail->AddAttachment($path); 
    $mail->Send(); 
    echo 'Message has been sent.'; 
} 
catch(Exception $e) 
{ 
    echo 'hata'.$e->getMessage(); 
} 
header("location:confirmation.php"); ?> 

,并在我的html页面:

<input type="text" name="UserMail" id="UserMail" size="30" /> 
<input type="text" name="UserName" id="UserName" size="30" /> 
<input type="text" name="UserSurname" id="UserSurname" size="30" /> 
<input type="text" name="UserTel" id="UserTel" size="30" /> 
<input type="password" name="UserPassword" id="UserPassword" size="30" /> 
+0

当我在php中运行print_r($ _ POST)时,它写入Array()。对不起,我是php.so的初学者,如果我犯了错误,警告我。 – rockenpeace 2012-07-17 11:28:53

+0

你刚刚给出了你的smtp信息。我为你编辑它。 – Martin 2012-07-17 11:29:46

+0

如果它正在写入Array(),则表单数据没有传递给它。你也应该向我们展示你的标记。 – Martin 2012-07-17 11:31:20

回答

0

好,它看起来像

a)你的$_POST超全球是空的(或至少不包含你认为它的作用)。这是在这种情况下首先要怀疑的。运行print_r($_POST)以查看内容。

这是不可能的假设 POST/GET变量进入。通过isset()检查这并检查它们是否包含你认为他们应该。简而言之,我们正在谈论验证。

b)听起来你的包装路径是错误的。再次,这很容易检查。运行echo file_exists('path/to/include') - 如果看不到1,则路径错误

+0

,我没有看到任何改变。 – rockenpeace 2012-07-17 11:33:56

+0

如果'file_exists(...)'不输出'1',那么文件的路径是错误的,正如我说的 – Utkanos 2012-07-17 11:34:22

0

使用isset验证$ _POST数组中是否存在键。

至于你失败了包括这意味着该文件是不是在你的get_include_path这样你就可以用set_include_path设置(注意这可能会影响你的其他亲戚包括),或者您可以使用absolute path

最后,在您的输入变量上使用mysql_real_escape_string,否则您非常容易受到SQL injection的影响。

样品

if (!isset($_POST['userName'], $_POST['key2'], .....)) { 
    // handle this error, you don't have the correct inputs 
} else { 

    // Validate inputs 

    // Escape inputs prior to inserting into database 
    $username = mysql_real_escape_string($_POST['userName']); 
    ... 
    ... 

    // Your queries 
} 
+0

我试图如果(!isset($ _ POST ['userName'],...)部分和这进入if语句,我已经使用mysql_real_escape_string,但任何东西都不会改变 – rockenpeace 2012-07-17 11:43:32

0

检查中,其形式操作的页面是这个页面,如果在页面输入标签

name属性是一样的,你正试图在这里找回什么。

<input type='submit' name='submit' value='register' /> 
</form> 

在register.php

if(isset($_POST['submit'])) 
{ 
    // value in quotes should be same as name attribute in input tag 
    $username=$_POST["username"] 
    .. 
} 

- 更新

<form method ='post' action='register.php' > 
    <input type="text" name="UserMail" id="UserMail" size="30" /> 
    <input type="text" name="fname" id="UserName" size="30" /> 
    <input type="text" name="lname" id="UserSurname" size="30" /> 
    <input type="text" name="telephone" id="UserTel" size="30" /> 
    <input type="password" name="userPassword" id="UserPassword" size="30" /> 
    </form 

,并在注册页面

if(isset($_POST['UserMail'])) 
{ 
    $mail =mysql_real_escape_strings($_POST['UserMail']); 
} 
if(isset($_POST['fname'])) 
{ 
    $mail =mysql_real_escape_strings($_POST['fname']); 
} 
if(isset($_POST['lname'])) 
{ 
    $mail =mysql_real_escape_strings($_POST['lname']); 
} 
+0

我已经在我的html页面中重写了名称属性,但是我仍然有同样的错误 – rockenpeace 2012-07-17 12:21:27

+0

你是否在'

' – 2012-07-17 12:25:14

+0

是的,我已经附上了这个表格:但我的方法部分与你不同 – rockenpeace 2012-07-17 12:31:17

0

在:

<input type="text" name="fname" id="UserName" size="30" /> 

变化name="fname"name="UserName"
对其他领域也一样。

$_POST使用name attribude,而不是ID


你必须检查,如果你$_POST变量使用isset()empty()设置。

例与isset()

if(isset($_POST['UserName'])) $username = $_POST['UserName']; 
else die("Username variable is not set."); 

例与empty()

if(!empty($_POST['UserName'])) $username = $_POST['UserName']; 
else die("Username variable is empty."); 

你应该在你心中的另一件事是,你应该使用之前逃脱你的字符串它通过使用进行SQL查询

例子:

$username = mysql_real_escape_string($_POST['UserName']); 

您可能还需要结合逃脱使用strip_tags()

+0

当我用if(isset($ _ POST ['UserName']] ))$ username = $ _POST ['UserName']; else die(“未设置用户名变量”);它写信息。 – rockenpeace 2012-07-17 12:19:27

+0

@rockenpeace这意味着你的变量是空的... – 2012-07-17 12:21:11

+0

你认为我在我的html页面中输入标签有错误吗?我的输入标签: \t \t \t \t \t rockenpeace 2012-07-17 12:28:33