I added a column to my database with SQL as follows:
ALTER TABLE comment_table ADD date_col Datetime NOT NULL;
I try to insert into the database with the following PHP but nothing gets inserted.
if(isset($_POST["submit"]))
{
$date_col = "test";//this will be DateTime later
$name = $_POST["name"];
mysqli_query($connection, "INSERT INTO comment_table (name, date_col) VALUES ('$name', '$date_col')");
}
$comsql = "SELECT * FROM comment_table";
$comres = mysqli_query($connection, $comsql);
while($comr = mysqli_fetch_assoc($comres)){
?>
<div class="row">
<p>Name: <strong><?php echo $comr['name']; ?></strong>This is the code that is being pointed to as undefined index. <?php echo $comr['date_col']; ?> </p>
<?php } ?>
</div>
The data I’m using for the date_col column is varchar and it should be Datetime but I don’t know if that’s the reason for the error. I would like to set $date_col equal to a Datetime expression for testing purposes but the formatting I chose wasn’t working either.