1

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

5
  • you're trying to update your entire database because of a missing WHERE clause; unless that's what you want to do but I doubt that. check for errors on the query. Commented Jul 24, 2017 at 2:10
  • where is $choseMonth that defined? question's unclear in many ways and where $today_date is used after and not use a POST array for the <select>. Commented Jul 24, 2017 at 2:10
  • I know that with WHERE my friend .. I have problem with options value in html tag when I put <?php $today_date = date('Y/m/d'); ?> in MySQl only see 0000-00-00 . And when I do same things with out OPTIONS VALUE all is ok Commented Jul 24, 2017 at 2:12
  • someone gave you an answer now, see that. Commented Jul 24, 2017 at 2:13
  • Can anyone write only one line code for put php variable in options value tag I mean on this <select name="date"><option value="<?php $todaydate = date('Y/m/d');>">1 Month</option> This is ok or not ? Commented Jul 24, 2017 at 2:21

3 Answers 3

2

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']
Sign up to request clarification or add additional context in comments.

4 Comments

Hmm I maybe some here is problem I go for check this .. Because when I use text input date in MySQL and when UPDATE all is ok .. Only not work when I use options value method
Yes this is help .. I only put variable I am not use echo for show what in value tag in html.. thx friend ..
If my answer solved your question, mark it as such by licking the check mark under the voting buttons.
I do that .. thx my dear friend on help .. and if you know now how I can add one month on $today_date variable that will save my time
0

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".

2 Comments

"Then, to fix the errors in your Javascript" - I don't see any JS.
I use only php for now .. and when I make this Date: <input type="text" name="dateEnd" value="<?php echo $date_end;?>"><br> this is work I can change manual date in text file and when update this in MySQL all is work .. Only don't want work with OPTIONS VALUE method
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.