Reputation: 19
I want put php date variable in html options value tag
this is my code:
<?php
$servername = "localhost";
$username = "root";
$password = "123456789";
$dbname = "db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_POST['submit'])){
$update = "UPDATE date SET date_end = '$choseMonth'";
if ($conn->query($update) === TRUE) {}
}
?>
<form action="update.php>" method="POST">
Use month <select name="choseMonth">
<option value="<?php $today_date = date('Y/m/d')?>">1 month + </option>
</select>
<input type="submit" name="submit" value="Update">
</form>
This code not work I don't know why .. I need put php variable in options value and I do that .. and when I look in MySql I see only 0000-00-00 I don't see date.
Please if any one can help me with this.
Thx
Upvotes: 1
Views: 4838
Reputation: 19
Thx Enstage on help ..
guys problem is only in echo.
When I want give some rezult in value in my variable I only save but that is not ok.
I must put echo for show variable
<select name="date">
<option value="<?php echo $date_end;?>">1 Month</option>
This is ansver
Upvotes: 0
Reputation: 2126
You're not echoing the variable...just storing something in it.
Do this:
<option value="<?php echo date('Y/m/d'); ?>">1 month + </option>
Then access the chosen option using the following:
$_POST['choseMonth']
Upvotes: 2
Reputation: 4306
You've got a few things wrong.
First, inside the same folder where the code with the <form>
tag exists, create a new file with name update.php
and move all your php code into that.
Then, to fix the errors in your HTML, make the following change to your code,
<form action="update.php" method="POST">
Notice you had an extra '>' character after "update.php".
Upvotes: 0