php - Insert into table doesn't go in Postgres

131

i have created a page to insert element into a database in php. At the beggining i start use with mySQL, and it works perfectly. Then I'm migrate to Postgres and so i had some problems. I change my code and i don't receive erros,but when i'm trying to insert my elements into the db, this remains empty.

this the structure of my table Prenotazione

CREATE TABLE public."Prenotazione"
(
  id integer NOT NULL DEFAULT nextval('"Prenotazione_id_seq"'::regclass),
  nominativo character(20),
  email character(20),
  oggetto character(200),
  nominativoi character(200),
  nominativoe character(200),
  emaili character(200),
  emaile character(200),
  data date,
  orario_inizio time without time zone,
  orario_fine time without time zone,
  stanza integer
)

this is my index.php

<form method="post" action="input.php">
                        <b>&ensp;Richiedente Conferenza:</b><br><br>
                        &ensp;Nominativo:<br>&ensp;<input type="text" name="nominativo" placeholder="Nome Cognome" size="20"><br>
                        &ensp;Email: <br> &ensp;<input type="email" name="email" size="20" placeholder="email"><br>
                        &ensp;Oggetto Conferenza:<br>&ensp;<textarea name="oggetto" rows="5" cols="40" placeholder="Specificare oggetto Videoconferenza"></textarea><br>
                        &ensp;Data: <br>&ensp;<input  type="date" name="data"  ><br>
                        &ensp;Orario Inizio: <br>&ensp;<input type="time" name="orario_inizio" min="09:30:00" max="16:30:00" ><br>
                        &ensp;Orario Fine: <br>&ensp;<input type="time" name="orario_fine" min="10:00:00" max="18:30:00"><br>

                        <br>
                        <b>&ensp;Partecipanti Interni </b>
                        <br>
                        <br>
                <div id="interni">
                    <div id="first">
                        &ensp;Nominativo:<br>&ensp;<textarea name="nominativoi" rows="5" cols="30" placeholder="Nome Cognome;"  ></textarea><br>
                        &ensp;Email:<br>&ensp; <textarea  name="emaili" rows="5" cols="30" placeholder="Inserire Email"></textarea><br> 
                      <br>
                      <br>
                    </div>
                </div>
                        <b>&ensp;Partecipanti Esterni </b>
                <div id="esterni">
                    <div id="first">
                               &ensp;Nominativo:<br>&ensp;<textarea name="nominativoe" rows="5" cols="30" placeholder="Nome Cognome;" ></textarea><br>
                                &ensp;Email:<br>&ensp;<textarea  name="emaile" rows="5" cols="30" placeholder="Inserire Email"></textarea><br> 
                      <br>
                    &ensp;&ensp;<input type="submit" value="Invia" > 
                        </form>

And finally the input.php

$checkdata = "SELECT count(*) as prenotato
  FROM Prenotazione
 WHERE data='$data'
   AND NOT ('$newTimeEnd' < orario_inizio OR orario_fine < '$orario_inizio')";

$querycheck = $dbh->prepare($checkdata);
$querycheck->execute();
$prenotato = $querycheck->fetch()[0];
var_dump($prenotato);
if ($prenotato == 0 AND $stanza == 0 ) { 

    $query1 = "INSERT INTO Prenotazione (nominativo,email,data,orario_inizio,orario_fine,oggetto,nominativoi,emaili,nominativoe,emaile,stanza) VALUES ('$nominativo','$email','$data','$orario_inizio','$newTimeEnd','$oggetto','$nominativoi','$emaili','$nominativoe','$emaile',1)";
    var_dump($query1);
    $result1 = $dbh->prepare($query1);
    $result1->execute();
    $rex = 1;
}
else if ($prenotato == 1){
    $query1 = "INSERT INTO Prenotazione (nominativo,email,data,orario_inizio,orario_fine,oggetto,nominativoi,emaili,nominativoe,emaile,stanza) VALUES ('$nominativo','$email','$data','$orario_inizio','$orario_fine','$oggetto','$nominativoi','$emaili','$nominativoe','$emaile',2)";
    $result1 = $dbh->prepare($query1);
    $result1->execute();
    $rex = 1;
}

I posted the part that are interesting to the problem. Thanks

The result of var_dump is :

NULL string(269) "INSERT INTO Prenotazione (nominativo,email,data,orario_inizio,orario_fine,oggetto,nominativoi,emaili,nominativoe,emaile,stanza) VALUES ('username','[email protected]','2018-10-03','09:30','12:30','object','username1','[email protected]','username2','[email protected]',1)"

180

Answer

Solution:

The problem is with your table name in double quotes. Don't use double quotes, or use them in every request.

You can verify your code here:

http://rextester.com/VIEH75483

Also, see more: Omitting the double quote to do query on PostgreSQL

People are also looking for solutions to the problem: "Trying to get property of non-object" error with PHP 7 (worked in PHP 5.4)

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.