提交后如何查询?

时间:2019-02-23 20:18:08

标签: php html mysql sql

我目前正在为我的私有服务器建立数据库,但是我的代码有问题:

我的提交按钮不起作用/将查询发送到数据库。 也许您可以给我一些根本原因的提示。

这是我的代码:

<?php
session_start();
//error_reporting(0);
ini_set('display_errors',1);
error_reporting(E_ALL);

require_once ('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
    {   
        header('location:index.php');
}
else{

    if(isset($_GET['edit']))
        {
            $editid=$_GET['edit'];
            $sql = "SELECT * from server where id = :editid";
    $query = $dbh -> prepare($sql);
    $query->bindParam(':editid',$editid,PDO::PARAM_INT);
    $query->execute();
    $result=$query->fetch(PDO::FETCH_OBJ);
    $cnt=1; 
        }



    if(isset($_POST['submit']))
      {
        $host = $_POST['host'];
        $hostport = $_POST['hostport'];
        $serverusr = $_POST['serverusr'];
        $serverpwd = $_POST['serverpwd'];
        //$id=$_POST['id'];
        //$host=$_POST['host'];
        //$hostport=$_POST['hostport'];
        //$serverusr=$_POST['serverusr'];
        //$serverpwd=$_POST['serverpwd'];
        //$designation=$_POST['designation'];
        //$editid=$_POST['id'];
        //$image=$_POST['image'];


        $sql = "UPDATE server SET 'host'=:host, 'hostport'=:hostport, 'serverusr'=:serverusr,'serverpwd'=:serverpwd  WHERE 'id'=:editid";
        //$sql = "UPDATE `server` SET `host` = '$host', `hostport` = '$hostport', `serverusr` = '$serverusr', `serverpwd` = '$serverpwd' WHERE `server`.`id` = $editid";
        //$sql= mysql_query("ALTER server SET host = '$host', 'hostport' = '$hostport', serverusr = '$serverusr', serverpwd = '$serverpwd'  WHERE id = '$idedit'");
        //$sql = "UPDATE server SET hostport = '$hostport' , host = '$host' , serverusr = '$serverusr' , serverpwd = '$serverpwd' where id = '1'";
        //$sql = "UPDATE server SET (host,hostport,serverusr,serverpwd) (:host, :hostport, :serverusr, :serverpwd) ";
        $query= $dbh -> prepare($sql);
        $query-> bindParam(':host', $host, PDO::PARAM_STR);
        $query-> bindParam(':hostport', $hostport, PDO::PARAM_STR);
        $query-> bindParam(':serverusr', $serverusr, PDO::PARAM_STR);
        $query-> bindParam(':serverpwd', $serverpwd, PDO::PARAM_STR);
        $query->execute();
        //$query->execute(array(":host"=>$host,":hostport"=>$hostport,":serverusr"=>$serverusr,":serverpwd"=>$serverpwd,":editid"=>$editid));
        $result=$query->fetch(PDO::FETCH_OBJ);
        $msg="server Host successfully updated!";
        $error="";
            //echo $sql;
        exit
    }    
}
?>

<!doctype html>
<html lang="en" class="no-js">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="theme-color" content="#3e454c">

    <title>Edit User</title>

    <!-- Font awesome -->
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <!-- Sandstone Bootstrap CSS -->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <!-- Bootstrap Datatables -->
    <link rel="stylesheet" href="css/dataTables.bootstrap.min.css">
    <!-- Bootstrap social button library -->
    <link rel="stylesheet" href="css/bootstrap-social.css">
    <!-- Bootstrap select -->
    <link rel="stylesheet" href="css/bootstrap-select.css">
    <!-- Bootstrap file input -->
    <link rel="stylesheet" href="css/fileinput.min.css">
    <!-- Awesome Bootstrap checkbox -->
    <link rel="stylesheet" href="css/awesome-bootstrap-checkbox.css">
    <!-- Admin Stye -->
    <link rel="stylesheet" href="css/style.css">

    <script type= "text/javascript" src="../vendor/countries.js"></script>
    <style>
.errorWrap {
    padding: 10px;
    margin: 0 0 20px 0;
    background: #dd3d36;
    color:#fff;
    -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
.succWrap{
    padding: 10px;
    margin: 0 0 20px 0;
    background: #5cb85c;
    color:#fff;
    -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
    box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
}
        </style>
</head>

<body>
    <?php include('includes/header.php');?>
    <div class="ts-main-content">
    <?php include('includes/leftbar.php');?>
        <div class="content-wrapper">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <h3 class="page-title">Edit server Server : <?php echo htmlentities($result->host); ?></h3>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="panel panel-default">
                                                <div class="panel-heading">Edit Info</div>
                                                    <?php if($error){?>
                                                            <div class="errorWrap"><strong>ERROR</strong>:<?php echo htmlentities($error); ?> </div>
                                                    <?php } else if($msg){?>
                                                            <div class="succWrap"><strong>SUCCESS</strong>:<?php echo htmlentities($msg); ?> </div>
                                                    <?php }?>
                                                        <div class="panel-body">
                                                            <form method="POST" action="" class="form-horizontal">
                                                                <div class="form-group">
                                                                        <label class="col-sm-2 control-label">Host<span style="color:red">*</span></label>
                                                                    <div class="col-sm-4">
                                                                        <input type="text" name="host" required placeholder="<?php echo htmlentities($result->host);?>">
                                                                    </div>
                                                                    <label class="col-sm-2 control-label">Port<span style="color:red">*</span></label>
                                                                    <div class="col-sm-4">
                                                                        <input type="text" id="hostport" class="form-control" value="<?php echo htmlentities($result->hostport);?>">
                                                                    </div>
                                                                    <label class="col-sm-2 control-label">User<span style="color:red">*</span></label>
                                                                    <div class="col-sm-4">
                                                                        <input type="text" id="serverusr" class="form-control" value="<?php echo htmlentities($result->serverusr);?>">
                                                                    </div>
                                                                    <label class="col-sm-2 control-label">Password<span style="color:red">*</span></label>
                                                                    <div class="col-sm-4">
                                                                        <input type="text" id="serverpwd" class="form-control" value="<?php echo htmlentities($result->serverpwd);?>">
                                                                    </div>
                                                                    <input type="submit" class="btn btn-primary" id="update" value="bla">
                                                                    <input type="submit" name="submit" value="submit"/>
                                                        </div>

                                                        </div>
                                </div>
                        </div>
                                                            </form>
                                    </div>
                                </div>
                            </div>
                        </div>



                    </div>
                </div>



            </div>
        </div>
    </div>
<?php
    $sql = "SELECT * from server where id = :editid";
    $query = $dbh -> prepare($sql);
    $query->bindParam(':editid',$editid,PDO::PARAM_INT);
    $query->execute();
    $result=$query->fetch(PDO::FETCH_OBJ);
    $cnt=1; 
?>

    <!-- Loading Scripts -->
    <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap-select.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/jquery.dataTables.min.js"></script>
    <script src="js/dataTables.bootstrap.min.js"></script>
    <script src="js/Chart.min.js"></script>
    <script src="js/fileinput.js"></script>
    <script src="js/chartData.js"></script>
    <script src="js/main.js"></script>
    <script type="text/javascript">
                 $(document).ready(function () {          
                    setTimeout(function() {
                        $('.succWrap').slideUp("slow");
                    }, 3000);
                    });
    </script>
</body>
</html>

如您所见,我尝试了几次查询...但没有任何效果。 我有一个名为configuration.php的单独站点,可以在其中将服务器成功添加到数据库中。

0 个答案:

没有答案