Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
can';t使用PHP更新postgres数据库_Php_Sql_Postgresql - Fatal编程技术网

can';t使用PHP更新postgres数据库

can';t使用PHP更新postgres数据库,php,sql,postgresql,Php,Sql,Postgresql,我正在尝试使用PHP创建crud应用程序,我已经成功地从postgres显示了我的数据表,但是当我尝试时,我得到了一些错误。这是我的代码: <?php require 'database.php'; $id = null; if ( !empty($_GET['Code_Espece'])) { $id = $_REQUEST['Code_Espece']; } if ( null==$id ) { header("Location: index.php"); } if ($_SERVER

我正在尝试使用PHP创建crud应用程序,我已经成功地从postgres显示了我的数据表,但是当我尝试时,我得到了一些错误。这是我的代码:

<?php require 'database.php'; $id = null; if ( !empty($_GET['Code_Espece'])) { $id = $_REQUEST['Code_Espece']; } if ( null==$id ) { header("Location: index.php"); } if ($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST)) {
$firstnameError = null; 

if (isset($_POST['Nom_Scien'])) {
                 $firstname = $_POST['Nom_Scien'];
            } 



 $valid = true;if (empty($firstname)) { $firstnameError = 'Please enter firstname'; $valid = false; }  
  if ($valid) { $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            $sql = 'UPDATE espece SET Nom_Scien = ? WHERE Code_Espece = ?';

            $q = $pdo->prepare($sql);
            $q->execute(array($firstname));
            Database::disconnect();
            header("Location: index.php");
        } 
       }else {

             $pdo = Database::connect();
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $sql = 'SELECT * FROM espece where "Code_Espece" = ?';
            $q = $pdo->prepare($sql);
            $q->execute(array($id));
            $data = $q->fetch(PDO::FETCH_ASSOC);
            $firstname = $data['Nom_Scien'];

            Database::disconnect();
        }

    ?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Crud-Update</title>
            <link href="css/bootstrap.min.css" rel="stylesheet">

    </head>
    <body>

<div class="container">

<div class="row">
</div>

<form method="post" action="update.php?Code_Espece=<?php echo $id ;?>">


</div>

<div class="control-group<?php echo!empty($firstnameError) ? 'error' : ''; ?>">
                    <label class="control-label">Nom Scientifique</label>

<br />
<div class="controls">
                        <input type="text" name="nomscientifique" value="<?php echo!empty($firstname) ? $firstname : ''; ?>">
                        <?php if (!empty($firstnameError)): ?>
                            <span class="help-inline"><?php echo $firstnameError; ?></span>
                        <?php endif; ?>
</div>
</div>

<div class="form-actions">
                    <input type="submit" class="btn btn-success" name="update" value="update">
                    <a class="btn" href="index.php">Retour</a>
</div>
            </form>
</div>
    </body>
</html>

积垢更新

更改
不相关:放入
退出
after
header(“Location:index.php”)谢谢;你的回答很有帮助
<input type="text" name="nomscientifique" value="<?php echo!empty($firstname) ? $firstname : ''; ?>">
<input type="text" name="Nom_Scien" value="<?php echo!empty($firstname) ? $firstname : ''; ?>">