I am learning php at the moment and have decided on creating a simple to do list that works just as I wanted it to do. But I decided a good idea would be to add in a dat stamp of when the item was added to the to do list, you know, to keep it organised.
Now when I manually insert an item via phpmyadmin and select todays date, the page displays the date as expected. Yet when I submit an item via my script on the front end the date is set to 0000-00-00 and I am at a point where I am a little stuck, I believe it is to do with the part below not inserting anything relating to the date, but I am not sure what do, I have tried to research but am a little confused:
$content = mysqli_real_escape_string($con, $_POST['content']); $sql="INSERT INTO items (content) VALUES ('$content')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } header('Location: index.php'); mysqli_close($con); The item is submitted via this form:
<form action="insert.php" method="post"> <input type="text" name="content"> <input type="submit" value="Add Item"> </form> And displayed with this:
$result = mysqli_query($con,"SELECT * FROM items"); while($row = mysqli_fetch_array($result)) { echo $row['added'] . "<br>" . $row['content']; echo "<br>"; echo "Mark as complete"; echo "<br>"; echo "<a onclick='confirmUser()' href='delete.php?id=" . $row['id'] . "'>Delete Item</a>"; echo "<br>"; echo "<a href='update.php?id=" . $row['id'] . "'>Edit Item</a>"; echo "<br>"; echo "<br>"; } mysqli_close($con);