尝试在html中运行PHP插入文件时出现错误404

时间:2019-04-22 17:43:14

标签: php codeigniter

我对MVC编码还很陌生,我正在尝试编写一个可以存储我的会员信息的简单Web应用程序。我有一个html表单,我想调用另一个名为“ insertmember.php”的文件,并且“ insertmember.php”应该采用从表单传入的参数并插入到我的mysql数据库中。问题是我不确定是否将“ insertmember.php”放置在错误的位置,或者是否错过了一些其他设置以使页面被拉起。

一切(Apache服务器和MySQL)都在运行XAMPP 我的“ insertmember.php”文件当前位于 E:\ xampp \ htdocs \ Firstwebapp \ application \ views

我的PHP文件

i1 <- order(names(evens)) # not sure if this should be avoided
map2(evens[i1], odds[i1], str_c, sep=" ")

我的HTML文件

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {

    function __construct()
    {
        parent::__construct();

    }

    function index()
    {

        $servername = "localhost";
        $username = "";
        $password = "";
        $dbname = "test";

        $conn = new mysqli($servername, $username, $password, $dbname);
        if ($conn->connect_error) 
        {
        die("Connection failed: " . $conn->connect_error);
        } 

        $sql = "SELECT member_ID, member_name, city_level, attack_power FROM member";
        //$result = $conn->query($sql);
        $data['result'] = $conn->query($sql);   
        $data['title'] = "GreenForest Member";
        $data['heading'] = "List of GreenForest members:";

        $this->load->view('home', $data);

        $conn->close();     


    }

}
?>

我的insertmember.php文件

<html>
<head>
<title>
<?=$title?>
</title>
</head>
<body>
<h3>Add New member</h3>
    <form action = "insertmember.php" method ="post"> 
        member_name  : <input type = "text" name = "member_name">
        <br/>
        city_level   : <input type = "text" name = "city_level">
        <br/>
        attack_power : <input type = "text" name = "attack_power">
        <br/>
        <input type =  "submit" value = "INSERT">
    </form>
<h3><?=$heading?></h3>

<table style="width:100%">
    <tr>
        <th>Member_ID</th>
        <th>Member_name</th>
        <th>City_level</th>
        <th>Attack_power</th>
    </tr>
<?php while($row = mysqli_fetch_assoc($result)) { ?>
    <tr>
        <th><?php echo$row['member_ID'] ?></th>
        <th><?php echo$row['member_name'] ?></th>
        <th><?php echo$row['city_level'] ?></th>
        <th><?php echo$row['attack_power'] ?></th>
    </tr>
<?php } ?>
</table>

</body>
</html>

我希望当我单击索引页面上的“插入”按钮时,表单中的值将进入数据库,并且页面将刷新以显示新记录

File Structure

1 个答案:

答案 0 :(得分:1)

此问题已解决。我必须进行更改 来自:

form action = "insertmember.php" method ="post"

至:

form action = "index.php/welcome/insertmember" method ="post"

对Swati的赞许指向我检查目录路径的方向