0

我在我的 php 应用程序中使用组件 datepicker,我想将 datepiker 组件的值影响到 php 数组的元素,如下所示:

<?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" => "");
    ?>

但是当我运行此页面时出现错误:

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

以及这一行的错误点:

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

我怎么能做到这一点谢谢,

4

1 回答 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" => "");
?>
于 2012-10-06T12:02:07.043 回答