1

我希望用户能够看到他们所有零工的名称和描述,然后能够从列表中选择每个零工的可用天数。本质上,我希望用户显示他们的奇数名称、描述、天数列表,然后是更新按钮,我希望在每个奇数作业的同一页面上重复此操作,以便用户可以看到他们的当前状态,更改它,选择一天并点击更新。

我正在尝试让多个列表在 php 中工作,但我不断收到此错误:

解析错误:语法错误,意外的 'DaysAvailable' (T_STRING),期待 ',' 或 ';'

这与以下形式的代码行有关:

<select name="DaysAvailable[]" size="5" multiple="multiple" id="DaysAvailable[]">

更新页面:

<?php   

            if (isset($_POST['OddJobName']) && isset($_POST['Description']) && isset($_POST['DaysAvailable']) && empty($errors) === true){//if (empty($_POST) === false && empty($errors) === true) { //if (isset(empty($_POST['OddJobName'])) && isset(empty($_POST['Description'])) && isset(empty($_POST['DaysAvailable'])) === false && empty($errors) === true)
            $daysavailable='';
            foreach ($_POST['DaysAvailable'] as $value)
            {

            $daysavailable .=$value." ";
            }

            $update_data = array (
                'MemberID'      => $MemberID,//$session_MemberID,//,$_SESSION['MemberID']
                'OddJobName'    => $_POST['OddJobName'],
                'Description'   => $_POST['Description'],
                'DaysAvailable' => $daysavailable, 

                );

                update_user ($update_data);

                if(success){
                 header('Location: member.php?username='.$username);
                 exit ();
                }
            } else if (empty($errors) === false){
                //otherwise output errors
                echo output_errors($errors);
            }


?>

同一页面上的表格:

<form action="" method ="post" enctype="multipart/form-data">
            <table width="100%" border="1" cellspacing="0" cellpadding="5">
                <td width="50%">
                <table width="100%" border="1" cellspacing="17" cellpadding="0">

<?php 

                    $result = mysql_query("SELECT * FROM `oddjob` WHERE `MemberID` = $MemberID");

                    while($row = mysql_fetch_assoc($result))
                    {
                    echo "<tr>
                        <td>
                        <p>Service Name:</p> 
                        </td>
                        <td>
                    <p>". $row['OddJobName']."</p>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <p>Description:</p>
                        </td>
                        <td>
                        <p>". $row['Description']."</p>
                        </textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        <p>Days Available(current week)*:</p>
                        <p>(hold Ctrl to select multiple)</p>
                        </td>
                        <td>
                        <select name="DaysAvailable[]" size="5" multiple="multiple" id="DaysAvailable[]">
                        "<option value="Monday">Monday</option>
                        <option value="Tuesday">Tuesday</option>
                        <option value="Wednesday">Wednesday</option>
                        <option value="Thursday">Thursday</option>
                        <option value="Friday">Friday</option>
                        <option value="Saturday">Saturday</option>
                        <option value="Sunday">Sunday</option>
                        </select>
                        </td>
                        <tr>
                </table>
                        <input type='submit'value='update'><input type='button'value='Back to profile' onClick="history.go(-1);return true;"><!--http://www.computerhope.com/issues/ch000317.htm-->
                </table>
                    </form>";
                        }
?>

更新功能:

function update_user($update_data){
            global $MemberID;
            $update = array();
            array_walk($update_data, 'array_sanitize');

            foreach($update_data as $field=>$data){ //loop through update data in update_info.php
                $update[] = '`' . $field . '` = \'' . $data . '\''; 
            }
            ("UPDATE `oddjob` SET " . implode(', ', $update). " WHERE `MemberID` = $MemberID") or die (mysql_error());

}

请帮我实现这个,谢谢。

4

1 回答 1

3

您使用 a"作为分隔符来回显大量 HTML。在您的 HTML 中,您有:

<select name="DaysAvailable[]" size="5" multiple="multiple" id="DaysAvailable[]">
                    "<option value="Monday">Monday</option>
                    <option value="Tuesday">Tuesday</option>
                    <option value="Wednesday">Wednesday</option>
                    <option value="Thursday">Thursday</option>
                    <option value="Friday">Friday</option>
                    <option value="Saturday">Saturday</option>
                    <option value="Sunday">Sunday</option>
                    </select>

第一个引号是 . 的结尾echo,其余的被传递给 PHP 进行解释。

对于这样的一大块代码,您可能希望改用HEREDOC

于 2013-04-11T17:00:52.713 回答