I have a website where you can upload news stories. Once the news is uploaded you can edit it. The issue is that when you edit the DATE form, it automatically displays it to "0000-00-00" on default.
So when I enter "blacklivesmatter" on the date form it should display a javascript error stating that "Date should be entered with YEAR-MONTH-DAY format only"
Here is how I think the code should look like for the error:
echo "<script language='javascript'> alert('Date should be entered with YEAR-MONTH-DAY format only'); window.location='editnews.php'; </script>";
Here is the code for the PHP page:
<?php
if(isset($_GET['id']))
{
$id = $_GET['id'];
$query = mysqli_query($con,"select * from news where ID = '$id'");
$re = mysqli_fetch_array($query);
}
?>
<form method="post" action="editnews_action.php">
<h3><b><u>Title:</b><input type="text" name="title" value="<?php echo $re['Title']; ?>"/><input type="hidden" name="id" value="<?php echo $re['ID']; ?>"/></h3>
<h3><b><u>Detail:</b><input type="text" name="desc" value="<?php echo $re['story']; ?>"/></h3>
<h3><b><u>Date:</b><input type="text" name="date" value="<?php echo $re['DATE']; ?>"/></h3>
<center>
<br>
<input type="submit" value="Submit" name="submit">
</form>
Here is the action page:
<?php require 'connect.php'; ?>
<?php
session_start();
if(isset($_POST['submit'])) {
$id = $_POST['id'];
$title=$_POST['title'];
$date= $_POST['date'];
$story=$_POST['desc'];
$q = mysqli_query($con,"update news set Title = '$title', story = '$story', DATE = '$date' where ID = '$id'");
if($q)
{
header("Location: adminside.php");
}
}
?>
Where should I put the javascript error at?