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,

6
  • 1
    Remove the dot before .datepicker Commented Oct 6, 2012 at 11:44
  • is .datepicker( "getDate" ) actually a JavaScript code? Commented Oct 6, 2012 at 11:51
  • is datepicker a PHP function or is a javascript function ? Commented Oct 6, 2012 at 11:51
  • like what you wrote @Zathrus : .datepicker( "getDate" ) is a javascript code Commented Oct 6, 2012 at 11:58
  • @Touki, I removed the dot but no changes Commented Oct 6, 2012 at 12:00

1 Answer 1

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" => "");
?>
Sign up to request clarification or add additional context in comments.

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.