I
I
Ilya2014-01-21 16:18:12
PHP
Ilya, 2014-01-21 16:18:12

Why is INSERT INTO query not being executed in SQLite in php?

I wrote a page with an input form, when the button is pressed, nothing happens. What am I doing wrong ?

<?php
     
if ($_POST)
{
     $db = sqlite_open("mybase1.db");       
     $today = date('Y-m-d');
           
     $namePr = $_POST["nameProject"];
     $commentPr = $_POST["comment"];
     // поля в базе :  name, comment - TEXT; autor - INTEGER;   dtb - DATE
     $query_insert = sqlite_query($db, "INSERT INTO projects (name, comment, autor, dtb) 
     VALUES ('".$namePr."', '".$commentPr."', ".$iduser.", '".$today."')");
           
     if (!$query_insert) {echo "всё плохо";}
     else
     {
          header("Location:index.php");
     }
     
}
     
?>
    <Html>
    <BODY>
    <form role="form">
      <div class="form-group">
     
        <label>Название  <small class="text-danger">*</small></label>
        <input class="form-control" name="nameProject">
      </div>
     
      <div class="form-group">
        <label>Описание</label>
        <textarea class="form-control"  rows="3" name="comment" > </textarea>
      </div>
      <div class="text-danger"></div>
      <button type="submit" class="btn btn-primary">Создать</button>
     
    </form>
     
     
    <script src="js/jquery.js"></script>
    </BODY>
    </HTML>

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
Nikolai Vasilchuk, 2014-01-21
@Zerpico

Regarding the error with date:
Find the line with in php.ini date.timezone, uncomment it and enter the required timezone. The list can be viewed here
After that, restart the web server.

K
kengos, 2014-01-21
@kengos

Specify method="post" in the form, otherwise it sends by default

N
Nikolai Vasilchuk, 2014-01-21
@Anonym

1. Use DBAL, at least PDO.
2. <button type="submit">does not submit the form. Use <input type="submit">
3. Why is there jQuery?

I
Immortal_pony, 2014-01-21
@Immortal_pony

$iduser is not declared anywhere, but you are trying to insert its value into the database.

I
Immortal_pony, 2014-01-21
@Immortal_pony

VALUES ('".$namePr."', '".$commentPr."', ".$iduser.", '".$today."')");

In this line, the dots after the variable name will be considered part of the variable name.
Can be rewritten like this:
Or like this (in double quotes, the values ​​of variables are also substituted, yes, they do not have to be closed / opened):
VALUES ('$namePr', '$commentPr', $iduser, '$today')");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question