提交时,不重定向到操作页面PHP

时间:2018-09-15 18:52:29

标签: php html post form-submit

当我单击“提交”时,它会重定向并显示“找不到对象”。但“网址”显示它在操作页面上。请帮助解决此问题.....

// addprograms.php-操作页面 //funtions.php-包含类和函数的公共页面

HTML代码

<div class="col-xs-12 col-sm-9 content">
    <div class="content-row">
      <div class="panel panel-default">
        <div class="panel-heading">
          <div class="panel-title"><b>Add Programs</b>
          </div>
        </div>
        <div class="panel-body">
            <form  role="form" class="form-horizontal" 
              action="../actions/addprograms.php" method="post">
            <div class="form-group">
              <label class="col-md-2 control-label">Title</label>
              <div class="col-md-10">
                <input type="text" required="" placeholder="Title" 
                   id="title" class="form-control" name="title">
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label" 
                  for="description">Description</label>
              <div class="col-md-10">
                <textarea required="" class="form-control" 
                  placeholder="Description" rows="10" cols="30" 
                  name="description"></textarea>
              </div>
            </div>
            <div class="form-group">
              <label class="col-md-2 control-label" 
               for="exampleInputFile">File input</label>
              <div class="col-md-10">
                  <input type="file" id="exampleInputFile" 
                   name="uploadedfile">
              </div>
            </div>
            <div class="form-group">
              <div class="col-md-offset-2 col-md-10">
                  <button class="btn btn-info" type="submit" 
                   name="addprogramsubmit">Submit</button>
              </div>
            </div>
          </form>
        </div>
      </div>

    </div>
   </div><!-- content -->

addprograms.php

<?php
require_once '../includes/functions.php';
    if(isset($_POST['addprogramsubmit'])){
           echo '12';
           exit();
     }
?>

这是我的functions.php文件 functions.php(不完整)

<?php
 session_start();
 class Auth extends DB {

 function login($tablename, $username, $password) {
    $result = mysqli_query($this->con, "SELECT username,password FROM 
              $tablename WHERE username='$username'") or die("Error: " . 
               mysqli_error($this->con));;

    $login_result = mysqli_fetch_array($result, MYSQLI_ASSOC);

    if (($login_result['username'] == $username) && 
       ($login_result['password'] == $password)) {

                     $_SESSION['login_id'] = $username;            
    }
    return true;
 }

}

class DB {

public $con;

function __construct() {
    $this->con = mysqli_connect("localhost", "root", "", "heatsds");
}

//    INSERT
function insert($tablename, $data = array(), $avoid_data = array()) {
    $i = 0;
    $fields = "";
    $values = "";
    foreach ($data as $col => $val) {
        if (!in_array($col, $avoid_data)) {
            if ($i === 0) {
                $fields .= "`" . $col . "`";
                $values .= "'" . $val . "'";
            } else {
                $fields .= ",`" . $col . "`";
                $values .= ",'" . $val . "'";
            }
        }
        $i++;
    }
    mysqli_query($this->con, "INSERT INTO $tablename ($fields) VALUES 
       ($values)");
}
function __destruct() {
    mysqli_close($this->con);
}

}

Image of the directory ERROR MESSAGE image

1 个答案:

答案 0 :(得分:0)

您的<form>action="../actions/addprograms.php",因此它将搜索addprograms.php文件。在您的列表中,只有actions.php。将actions.php的内容移至addprograms.php,这应该可以工作。