jeudi 24 mars 2016

Inser checkbox inputs into a postgresql with php

I'm trying to introduce the value of a checkbox into my database in postgresql. I created the table account with a colum named: getrequest which is the type boolean.

I'm using the code below, but I'm getting the following error:

Error with query: ERROR: invalid input syntax for type boolean: "" LINE 1: ...account(getrequest) VALUES('', ... ^

Any help would be highly appreciated.

Thanks

<?php

$getrequest  =  "";

    $db = pg_connect('host=localhost dbname=test user=myuser password=mypass');

    $getrequest = pg_escape_string($_POST['getrequest']);

    $query = "INSERT INTO account(getrequest) VALUES('" . $getrequest . "')";

             $result = pg_query($db, $query);
        if (!$result) {
           $errormessage = pg_last_error();
               echo "Error with query: " . $errormessage;
           exit();
          }

            $getrequest =  "";

     pg_close();


function test_input($data) {
 $data = trim($data);
 $data = stripslashes($data);
 $data = htmlspecialchars($data);
 return $data;
}

?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">

<input type="checkbox" name="getrequest" value="getrequest" class="regular-checkbox">I get a request<br> 

<br>

<input type="submit" name="submit" value="SAVE">
</form>




Aucun commentaire:

Enregistrer un commentaire