Im trying to update my table news dynamically.
And its working fine, but I want to show in my form the current values that my news has, so Im using inside my value = <?php echo $read['title'] ; ?>
But with date, Im getting two errors:
Im getting this error inside my input: Notice: Undefined variable: spanish and Undefined variable: english
I understand erros, but I wanted to ask you, if you know how I can solve this, I know if I repeat definition of my variables "spanish and english" inside my date value, it works, but it not seems correct to repeat this variables.
Do you know how I con solve this using only one definition for $english and $spanish variables??
<?php
if(isset($_POST['sendForm']))
{
$f['title'] = $_POST['title'];
$f['date'] = $_POST['date'];
if(in_array('',$f))
{
echo 'Fill all fields';
}
else
{
$english = array(); //here I have some words
$spanish = array();
$result_date = str_ireplace ($english , $spanish, $f['date']);
$date = DateTime::createFromFormat('l, j F, Y', $result_date);
$date = $date->format('Y-m-d H:i:s');
$update = $pdo->prepare("UPDATE news set title=:title, date=:date WHERE id = :id");
$update->bindValue(':title', $f['title']);
$update->bindValue(':date', $date);
$update->bindValue(':id', '20');
$update->execute();
}
}
?>
<form action="" method="post" enctype="multipart/form-data">
<label class="line">
<span>Title:</span>
<input type="text" name="title" value="<?php echo $read['title'] ; ?>" />
</label>
<label class="line">
<span>Date:</span>
<input type="text" name="date" value="
<?php
$date = new DateTime($read['date']);
$result_date = str_ireplace($spanish , $english, $date->format('l, j F, Y'));
echo $result_date;
?>" />
</label>
<input type="submit" value="Submit" name="sendForm"/>
</form>