postgres更新脚本使用PHP无法正常工作

时间:2015-03-30 18:08:12

标签: php postgresql

我想使用php更新我的表postgresql中的行,我不能更新我的行,并且没有显示错误,我的脚本中没有看到问题!这是我的表结构:

CREATE TABLE chercheur
(
  nomcher text,
  idfcher text NOT NULL,
  precher text,
  passcher text,
  mailcher text,
  gradcher text,
  naisscher date,
  lieucher text,
  divicher text,
  CONSTRAINT "Chercheur_pkey" PRIMARY KEY (idfcher)
)

和程序:

    $conn = pg_pconnect("dbname=postgres host=localhost port=5432 user=postgres password=postgres");

    if ($conn) {
        //print "Successfully connected to database: " . pg_dbname($conn) .
        // " on " .  pg_host($conn) . "</br>\n";


        $id = pg_escape_string($_POST['identif']);


        $result = pg_query($conn, "SELECT * from chercheur WHERE idfcher='" . $id . "';");
    } else {
        print pg_last_error($conn);
        exit;
    }
    if (!$result) {
        $errormessage = pg_last_error();
        echo "Error with query: " . $errormessage;
        exit();
    } else {
        while ($myrow = pg_fetch_row($result)) {

            echo '<hr><h2>Informations du chercheur trouvé:</h2>';
            echo '<table>
    <tr>
        <td><label for="nom">Nom du chercheur</label></td>
        <td><input value="' . $myrow[0] . '" name="nom" id="nom" type="text" /></td>
    </tr>
    <td> <label for="prenom">Prenom du chercheur</label></td>


    <td> <input value="' . $myrow[2] . '" name="prenom" id="prenom" type="text" /></td>
    </tr>
    <tr>
        <td><label for="user">Identifiant </label></td>
        <td><input value="' . $myrow[1] . '" name="user" id="user" type="text" /></td>
    </tr>
    <tr>
        <td><label for="pass">Mot de passe</label></td>
        <td><input value="' . $myrow[3] . '" name="pass" id="pass" type="password" /></td>
    </tr>

    <td><label for="mail">Email  du chercheur</label></td>
    <td><input value="' . $myrow[4] . '" name="mail" id="mail" type="email" /></td>
    </tr>
    <td><label for="grade">Grade</label></td>
    <td> <input value="' . $myrow[5] . '" name="grade" id="grade" type="text" /></td>
    </tr>
    <tr>
        <td><label for="naiss">Date de naissance</label></td>
        <td><input value="' . $myrow[6] . '" name="naiss" id="naiss" type="date" /></td>
    </tr>
    <tr>
        <td><label for="lieu">Lieu de naissance</label></td>
        <td><input value="' . $myrow[7] . '" name="lieu" id="lieu" type="text" /></td>
    </tr>
    <tr>
        <td><label for="divis">Division</label></td>
        <td><input value="' . $myrow[8] . '" name="divis" id="divis" type="text" /></td>
    </tr><tr><td>  &nbsp;&nbsp;&nbsp;&nbsp;          </td></tr>
    <tr>
        <td></td>  <td><button name="submit2" id="submit2" type="submit" >Mettre à jour</button>

    <button name="annuler" id="annuler" type="reset" >Réinitialiser</button></td>
</tr>
</table>';
            if ((isset($_POST['submit2']))) {
                $idf = pg_escape_string($_POST['user']);
                $pass = pg_escape_string($_POST['pass']);
                $name = pg_escape_string($_POST['nom']);
                $pre = pg_escape_string($_POST['prenom']);
                $mail = pg_escape_string($_POST['mail']);
                $naissance = pg_escape_string($_POST['naiss']);
                $lieu = pg_escape_string($_POST['lieu']);
                $division = pg_escape_string($_POST['divis']);
                $gr = pg_escape_string($_POST['grade']);


                $result = pg_query($conn, "UPDATE  chercheur SET  nomcher='" . $name . "' and
precher='" . $pre . "' and passcher='" . $pass . "' and mailcher='" . $mail . "' and naisscher=date('" . $naissance . "')
and lieucher='" . $lieu . "' and divicher='" . $division . "'and gradcher='" . $gr . "'
where idfcher='" . $idf . "';");
                if (!$result) {
                    $errormessage = pg_last_error();

                    echo "Error with query: " . $errormessage;
                    exit();
                } else {
                    echo "mise à jour avec succès";
                }
            }
        }


    }
    pg_free_result($result);


    pg_close();

?>

0 个答案:

没有答案