【发布时间】:2017-02-28 15:23:22
【问题描述】:
根据下面的教程,我正在尝试注册:
https://www.youtube.com/watch?v=T9MvEFcJyQw
我是 PHP 新手,需要一些帮助。
现在显示这些错误:
注意:未定义索引:第 6 行 C:\wamp64\www\register.php 中的 Nachname
注意:未定义索引:第 7 行 C:\wamp64\www\register.php 中的电子邮件
注意:未定义索引:第 8 行 C:\wamp64\www\register.php 中的 Geburtstag
注意:未定义索引:第 9 行 C:\wamp64\www\register.php 中的 Name der Schule
警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 18 行的 C:\wamp64\www\register.php 中给出
警告:array_push() 期望参数 1 为数组,在第 36 行的 C:\wamp64\www\register.php 中给出 null
这是我的 php 代码:
<?php
require "init.php";
$name = $_POST ["name"];
$name = $_POST ["surename"];
$email = $_POST ["Email"];
$birthdate = $_POST ["Geburtstag"];
$name = $_POST ["Name der Schule"];
$user_name = $_POST ["user_name"];
$password = $_POST ["password"];
$sql = "select * from user_info where email like '".$email."';";
$result = mysqli_query($con,$sql);
$respons = array();
if (mysql_num_rows ($result)>0)
{
$code = "req_faild";
$message = "User already exist";
array_push($response,array("code"=>$code, "message"=>$message));
echo json_encode($response);
}
else
{
$sql = "insert into user_info values('".$name."','".$name."','".$email."','".$birthdate."','".$name."','".$user_name."','".$password."');";
$result = mysqli_query($con,$sql);
$code = "req_success";
$message = "Thank your for register with us. NOw you can login.";
array_push($response,array("code"=>$code, "message"=>$message));
echo json_encode($response);
}
mysqli_close($con);
?>
这是我的 html 代码:
<html>
<body>
<form action="register.php" method="post">
<table>
<tr>
<td>Name: </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Surename: </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>Email: </td><td><input type="text" name="email"/></td>
</tr>
<tr>
<td>Birthday: </td><td><input type="text" name="birthday"/></td>
</tr>
<tr>
<td>Name of your School: </td><td><input type="text" name="name"/></td>
</tr>
<tr>
<td>User Name: </td><td><input type="text" name="user_name"/></td>
</tr>
<tr>
<td>Password: </td><td><input type="text" name="password"/></td>
</tr>
<tr>
<td><input type="submit" value="Register"/></td>
</tr>
</tanle>
</form>
</body>
</html>
谁能帮帮我?
【问题讨论】:
-
Nachname甚至不在您显示的 PHP 代码中,因此 that 代码不会导致 that 错误。 // 当然,您的表单字段名称必须与您之后使用的键匹配,以尝试从 $_POST 数组中获取值。你有 f.e.name="birthday"在您的表单中,但随后您尝试访问$_POST ["Geburtstag"]...您不能只翻译一半然后期望它仍然有效,应该很明显。 -
使用前请确保设置了值:mysql_num_rows:可以加:
if(isset($result)) -
你能告诉我这里出了什么问题吗:if (mysql_num_rows ($result)>0)