HTML表单提交问题

时间:2019-05-19 11:44:35

标签: php html submit form-submit submit-button

<!DOCTYPE html>
<html>
    <head>
        <title> Login Page</title>
        <link rel="stylesheet" type="text/css" href="dashboard.css">    
    </head>
    <body>
        <div id="form">
            <form action="http://localhost/students_home/stud.php" method="post">
                <p>
                    <label id="no1"><b>User-name : </b></label>
                    <input type="text" id="name" name="name"/>
                </p>            
                <p>
                    <label id="no2"><b>Password : </b></label>
                    <input type="password" id="password" name="password">
                </p>
                <p>
                    <input type="submit" id="btn" name="login">                
                </p>
            </form>
        </div> 
    </body>
</html>

这是我的代码。它不接受在表单中输入的任何值。如果我在提交表单时未输入任何内容,那么它将起作用。我无法理解正在发生的事情,应该如何纠正?请帮助

我试图重写代码,并复制粘贴与此代码完全相同的工作代码。由于某种原因,这个特定功能无法正常工作。

这里是stud.php文件的代码:

<!DOCTYPE html>
<html>
<head>
    <title>Admission letter</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
    <?php
        $con=mysqli_connect("localhost","root","param2000","students home");

        //now successfully connected. try catch block was to check for errors
        //Getting values from the login page
        $name=$_POST['name'];
        $password=$_POST['password'];

        //to prevent mysql injection
        $name=stripcslashes($name);
        $password=stripcslashes($password);

        //$password = hash('sha256', (get_magic_quotes_gpc() ? stripslashes($password) : $password));

        $name=mysqli_real_escape_string($con,$name);
        $password=mysqli_real_escape_string($con,$password);

        $result=mysqli_query($con,"select * from students where name='$name' and passsword='$password'")
            or die("Failed to take answers from database".mysqli_error($con));
        $row=mysqli_fetch_array($result);
        print_r($row);

       if($row['name']==$name && $row['password']==$password){
            ob_start();
            include('fpdf library 1.81/fpdf.php');
            $pdf=new FPDF();
            $pdf->AddPage();
            $pdf->SetFont('Arial','B','15');
            $text="Hello , ".$row['name'];
            $pdf->Cell(40,10,$text);
            $pdf->Ln();
            $text="Your Id number is : ".$row['Id number'];
            $pdf->Cell(40,10,$text);
            $pdf->Ln();
            $text="You are in batch : ".$row['Batch'];
            $pdf->Cell(40,10,$text);
            $pdf->Ln();
            $text="You are enrolled in year : ".$row['Year'];
            $pdf->Cell(40,10,$text);
            $pdf->Ln();
            $text="Your marks in test 1 : ".$row['Marks(test)'];
            $pdf->Cell(40,10,$text);
            $pdf->output();
            ob_end_flush();
        }
        else{
            header("Location: dashboard.php"); /* Redirect browser */
      }
    ?>

</html>

1 个答案:

答案 0 :(得分:0)

首先:
建议您在表单操作中输入文件名,而不要输入URL。 像:
<form action="stud.php" method="post">
2,
问题也可能出在处理表单的stud.php文件中。我会说检查该文件是否有任何错误。您可以在stud.php文件中使用:echo error_get_last();

您介意也显示stud.php文件的代码,以便查看该文件的功能以及它如何处理表单。

以诚挚的问候,