dongya2030 2015-04-05 19:00
浏览 34

too long

I am new about php and trying to create a register and login script, but i am facing some problem. when I am submitting registration form it is showing a error message:

Notice: Undefined index: register in C:\xampp\htdocs\hms3\actions.php on line 8

    <?php
    require_once("config.php");
    if(isset($_REQUEST['login']))
    {
        $obj=new configs;
        $obj->login();
    }
    elseif($_REQUEST['register'])
    {
        $obj= new configs;
        $obj->register();
    }
?>

above codes are in actions.php

    <?php
session_start();
$_POST['msg']="works";
class configs
{
    function login()
    {
    $con = mysqli_connect("localhost","dbuser","12345","hms");
    // Check connection
    if (mysqli_connect_errno()) 
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

        $username=$_REQUEST['username'];
        $password=$_REQUEST['password'];
        $result = mysqli_query($con,"SELECT * FROM user WHERE username = '".$username."'");

        $row = mysqli_fetch_array($result);
                $_SESSION['username']=$row['username'];
                $_SESSION['password']=$row['password'];

        if($username==$row['username'] && $password==$row['password'])
        {
            header("location:index.php");
        }
        else
        {
            header("location:Login.php?msg=usernamepasswordincorrect");
        }
    }

    function register()
    {
        $username=$_REQUEST['username'];
        $password=$_REQUEST['password'];

        if($username!=""&&$password!="")
        {
            $con = mysqli_connect("localhost","dbuser","12345","hms");
            // Check connection
            if (mysqli_connect_errno()) 
            {
            echo "Failed to connect to MySQL: " . mysqli_connect_error();
            }

            $username=$_REQUEST['username'];
            $password=$_REQUEST['password'];

            $result = mysqli_query($con,"SELECT * FROM user WHERE username = '".$username."'");
            $row = mysqli_fetch_array($result);
            if($row['username']!=$username)
            {
            mysqli_query($con,"INSERT INTO user (username, password) VALUES ('$username', '$password')");
            header("location:register.php?msg=success");
            }
            else
            {
                header("location:register.php?msg=usernameexists");
            }
        }
        elseif($username=""&&$password="")
        {
            header("location:register.php?msg=both");
        }
    }
}
?>

Registration Form HTML codes below:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Register Here</title>
</head>
<body>
<center>
<?php
if(isset($_REQUEST['msg']))
{
    if($_REQUEST['msg']=='success')
    {
        echo "Registration Successful. Now You Can Login To Your Account <a href='login.php'>Here</a>";
    }
    elseif($_REQUEST['msg']=='usernameexists')
    {
        echo "Username Already Exists";
    }
    elseif($_REQUEST['msg']=='both')
    {
        echo "Please Enter A Username And Password";
    }
}
?>
<h1>Register Here</h1>
<form action="actions.php" method="post">
<fieldset style="width: 650px;">
<legend>Patient Details</legend>
<table>
<tbody><tr>
<td>
<label for="firstname">First Name:</label>
</td>
<td><input name="firstname" type="text"></td>
<td><label for="lastname">Last Name:</label></td>
<td><input name="lastname" type="text"></td>
</tr>
<tr>
<td>
<label for="occupation">Occupation:</label>
</td>
<td><input name="occupation" type="text"></td>
<td><label for="religion">Religion:</label></td>
<td><input name="religion" type="text"></td>
</tr>
<tr>
<td><label for="birthday">Date of Birth</label></td>
<td><input name="birthday" type="text"></td>
<td><label for="sex">Sex</label></td>
<td><input name="sex" value="male" checked="" type="radio">Male
<input name="sex" value="female" type="radio">Female
</td>
</tr>
<tr>
<td><label for="telephone">Telephone:</label></td>
<td><input name="telephone" type="text"></td>
<td><label for="mobile">Mobile:</label></td>
<td><input name="mobile" type="text"></td>
</tr>
<tr>
<td><label for="presentaddress" />Present Address:</label></td>
<td><textarea name="presentaddress"></textarea></td>
<td><label for="permanentaddress" />Permanent Address:</label></td>
<td><textarea name="permanentaddress"></textarea></td>
</tr>
</tbody></table></fieldset>
<fieldset style="width: 650px;">
<table>
<legend>Medical Details</legend>
<tr>
<td><label for="diseasestype" />Diseases Type:</label></td>
<td><input type="text" name="diseasestype" /></td>
<td><label for="diseases" />Diseases Name:</label></td>
<td><input type="text" name="diseases" /></td>
</tr>

<tr>
<td><label for="referd" />Refd. By:</label></td>
<td><input type="text" name="refd" /></td>
<td><label for="specialist" />Specialist:</label></td>
<td><input type="text" name="specialist" /></td>
</tr>
<tr>
<td><label for="serial" />Serial Number:</label></td>
<td><input type="text" name="serial" /></td>
<td><label for="payment" />Payment:</label></td>
<td><input type="text" name="payment" /></td>
</tr>
<tr>
<td><label for="ward" />Ward No.:</label></td>
<td><input type="text" name="ward" /></td>
<td><label for="bed" />Bed No.:</label</td>
<td><input type="text" name="bed" /></td>
</tr>
<tr>
<td><label for="username" />Username:</label></td>
<td><input type="text" name="username" /></td>
<td><label for="password" />Password:</label</td>
<td><input type="password" name="password" /></td>
</tr>
</table>
</fieldset>
<input type="submit" value="Submit Details" />
</form>
</center>
</body>
</html>

Now I am trying to show profile info when a user logged in.

<?php
session_start();
if(isset($_SESSION['username']))
{
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Only People Who Are Logged In Will See This Page</title>
</head>
<body>
<center>
<?php
$servername = "localhost";
$username = "dbuser";
$password = "12345";
$dbname = "hms";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT firstname, lastname FROM patient";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
     echo "<table><tr><th>ID</th><th>Name</th></tr>";
     // output data of each row
     while($row = $result->fetch_assoc()) {
         echo "<tr><td>" . $row["id"]. "</td><td>" . $row["firstname"]. " " . $row["lastname"]. "</td></tr>";
     }
     echo "</table>";
} else {
     echo "0 results";
}

$conn->close();
?>
</center>
</body>
</html>';
}
else
{
    header("location:login.php?msg=you");   
}
?>
  • 写回答

1条回答 默认 最新

  • dongle7553 2015-04-05 19:10
    关注

    this error

    Notice: Undefined index: register in C:\xampp\htdocs\hms3\actions.php on line 8

    is because in your form there is not any element with name=register so when you want use $_REQUEST['register'] say error

    评论

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值