0

我是 PHP MVC 的新手,并且真的开始理解这个概念。我在文本框中显示当前用户名时遇到问题。

请在下面检查我的代码:

<?php
//require_once (Path::controllerClassPath(). "Summarycontroller.php");
require_once (Path::controllerClassPath(). "CalendarController.php");

//$summary = new SummaryController($this->sessionHandler->getUserId());
$calendar = new CalendarController($this->sessionHandler);

$userId = $this->sessionHandler->getUserId();
?>

<div id="fileleaverequestholiday">
<?php 
echo '<form name="fileleaverequestholidayform" id="fileleaverequestholidayform" action="" method="post">';
echo '<fieldset class="fileleavetables"><legend>Request Leave</legend>';
echo '<table id="fileleaverequesttable">';
echo '<tr>';
//echo '<td class="fileleavetd">Name:</td><td class="fileleavetd"><input id="fileleaveemployeename" type="text" name="fileleaveemployeename"/></td>';
echo '<td class="fileleavetd">Name:</td><td class="fileleavetd"><input id="fileleaveemployeename" type="text" name="fileleaveemployeename" value="'.$retval.'" /> </td>'; ?>

我已经注释掉了这段代码:

    $userId = $this->sessionHandler->getUsername();

    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass);
    if(! $conn )
    {
        die('Could not connect: ' . mysql_error());
    }

    $sql = "SELECT employee_name FROM employee WHERE employee_username = $userId" ;

    mysql_select_db('test');
    $retval = mysql_query( $sql, $conn );
    print($retval);
    if(! $retval )
    {
        die('Could not update data: ' . mysql_error());
    } 

更新:

<div id="fileleaveinsertholiday">
<?php 
if(isset($_POST['fileleaveemployeename'], 
            $_POST['leavetype'], 
            $_POST['filerequestreason'],
            $_POST['filerequeststartdate'])){

if(isset($_POST['filerequestenddate'])){
    if($_POST['filerequestenddate'] > $_POST['filerequeststartdate']){
        $result = $calendar->manageFileHoliday(
                        $_POST['fileleaveemployeename'], 
                        $_POST['leavetype'], 
                        $_POST['filerequestreason'],
                        $_POST['filerequeststartdate'], 
                        '1',
                        $_POST['filerequestenddate']
                     );
        if($result == Status::INSERT_SUCCESS){
            echo '<b>Entry for '.$_POST['fileleaveemployeename'].' from '.$_POST['filerequeststartdate'].' to '.$_POST['filerequestenddate'].' submitted.</b>';         
        }
        else{
            echo '<b>Entry was not submitted. No such name exists in the list.</b>';
        }            
    }
    else{
        echo '<b>Entry was not submitted. Invalid Date Range.</b>';
    }
}
else{
        $result = $calendar->manageFileHoliday(
            $_POST['fileleaveemployeename'], 
            $_POST['leavetype'], 
            $_POST['filerequestreason'],
            $_POST['filerequeststartdate'],
            $_POST['requestduration']
         );
        if($result == Status::INSERT_SUCCESS){
            echo '<b>Entry for '.$_POST['fileleaveemployeename'].' on '.$_POST['filerequeststartdate'].' submitted.</b>';
        }
        else{
            echo '<b>Entry was not submitted. No such name exists in the list.</b>';
        }   
}   
}
?>
</div>

因为当我添加这个时,我的页面没有正确显示。有什么帮助吗?谢谢。

4

1 回答 1

1

试试下面的代码..

mysql_select_db('test', $conn)

$retval = mysql_query( $sql);

代替

mysql_select_db('test');

$retval = mysql_query( $sql, $conn );
于 2012-12-17T11:20:15.300 回答