Answer the question
In order to leave comments, you need to log in
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
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.
1. Use DBAL, at least PDO.
2. <button type="submit">
does not submit the form. Use <input type="submit">
3. Why is there jQuery?
$iduser is not declared anywhere, but you are trying to insert its value into the database.
VALUES ('".$namePr."', '".$commentPr."', ".$iduser.", '".$today."')");
VALUES ('$namePr', '$commentPr', $iduser, '$today')");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question