0

I use the component datepicker in my php application and I want to affect the value of the datepiker component to an element of a php array like this :

<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST")
        $wish = array("id" => $_POST["wishID"], "description" => $_POST["wish"], "due_date" => .datepicker( "getDate" ));
    else
    if (array_key_exists("wishID", $_GET))
        $wish = mysqli_fetch_array(WishDB::getInstance()->get_wish_by_wish_id($_GET["wishID"]));
    else
        $wish = array("id" => "", "description" => "", "due_date" => "");
    ?>

but I have an error when I run this page :

Parse error: syntax error, unexpected 'getDate' (T_STRING), expecting ')' in C:\wamp\www\PhpProject1\editWish.php on line 48

and the error points on this row :

"due_date" => .datepicker( "getDate" )

how I can achieve this thanks,

simonTifo
  • 307
  • 3
  • 12
  • 29

1 Answers1

1

You cannot intermix PHP and JavaScript code the way you tried. They are completely different languages, even processed on different parts of the application (JavaScript is client-side, PHP is server-side).

What you need to do is actually use the .datepicker( "getDate" ) on your HTML page to populate an element in the same form where wishID and wish inputs are present (like a hidden input, or even text input) and then sumbit that form along to your PHP script. Then you will be able to do something like:

<?php
    if ($_SERVER["REQUEST_METHOD"] == "POST")
        $wish = array("id" => $_POST["wishID"], "description" => $_POST["wish"], "due_date" => $_POST['your_date_input_field']);
    else
    if (array_key_exists("wishID", $_GET))
        $wish = mysqli_fetch_array(WishDB::getInstance()->get_wish_by_wish_id($_GET["wishID"]));
    else
        $wish = array("id" => "", "description" => "", "due_date" => "");
?>
Zathrus Writer
  • 4,311
  • 5
  • 27
  • 50