2012-07-19 59 views
0

我的代码有2个问题。但首先,这里的一套完整的代码PHP:日期选择器不起作用,按钮显示错误

<html> 

<title>IMS:MPP | Home</title> 

<script type="text/javascript"> 

     function PopupCenter(pageURL, title,w,h) 
      { 
       var left = (screen.width/2)-(w/2); 
       var top = (screen.height/2)-(h/2); 
       var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left); 
      } 

      var state = new Array(); 
      for (i=0; i<1; i++) { 
       state[i] = "none"; 
       } 



</script> 

<head> 
<link href="officerStyle.css" rel="stylesheet" type="text/css" media="screen" /> 
</head> 

<script type="text/javascript" src="jsDatePick.min.1.3.js"></script> 

<script type="text/javascript"> 
    window.onload = function(){ 

     new JsDatePick({ 
      useMode:2, 
      target:"inputField", 
      cellColorScheme: "armygreen", 
      limitToToday:true, 
     }); 
      }; 

      $(function() { 
      $("#inputField1").JsDatePick(); 
      } 
      ) 
      ; 


      </script> 



<!-- End --> 

<?php 


if(isset($_REQUEST['inputField1'])) 
    $inputField1 = $_REQUEST['inputField1']; 
else 
    $inputField1 = ""; 

include('global.php'); 

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="mpp"; // Database name 
$tbl_name="userinfo"; // Table name 

// Connect to server and select database. 
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB"); 

//$_SESSION['myusername'] = $row['Username']; 

//$_SESSION['mypassword'] = $row['UserID']; 
$myusername=$_SESSION['myusername']; 
//$mypassword=$_SESSION['mypassword']; 

//require("mainlogin.php"); 
//$id = $_SESSION['myusername']; //Get user's ID 
$result = mysql_query("SELECT * FROM $tbl_name where Username='$myusername'"); 
$row = mysql_fetch_assoc($result); 

$type = $row['UserType']; 
?> 

<body> 

<div id="wrapper"> 
    <div id="header"> 
    <img id="logos" src="images/logo.png" style="opacity:0.7;filter:alpha(opacity=70)" 
     onmouseover="this.style.opacity=0.7;this.filters.alpha.opacity=70" 
     onmouseout="this.style.opacity=1;this.filters.alpha.opacity=100" border="none"/> 

    <a href="logout.php" onclick="return confirm ('Are you sure you want to Log Out?')"><img id="out" src="images/Outbtn.png" style="opacity:0.7;filter:alpha(opacity=70)" 
       onmouseover="this.style.opacity=1;this.filters.alpha.opacity=100" 
       onmouseout="this.style.opacity=0.7;this.filters.alpha.opacity=70" border="none"/></a> 
    </div> 

    <div id="page"> 
     <div id="page-bgbtm"> 
      <div id="menu"> 

       <?php 

       /*------------------------------------------------------------ Encoder ------------------------------------------------------------*/ 

        if ($type=="Encoder"){ 
        //Navigation 
         echo " <ul> 
           <li class='current_page_item'> <a href='#'>Home</a> </li> 
           <li> <a href='SalesOfficer.php'>Sales</a> </li> 
           <li> <a href='PromoOfficer.php'>Promo</a> </li> 
           <li> <a href='BankOfficer.php'>Bank</a> </li> 
           <li> <a href='PlanOfficer.php'>Plan</a> </li> 
           <li> <a href='User.php'>User</a> </li> 
           <li> <a href='Client.php'>Client</a> </li> 
           </ul> 
           </div>"; 

        //Texts 
         echo " <br/><br/><h1 class='title'><a href='#'>Welcome</a></h1> 
         <div class='entry'>"; 
         echo "<h3>" . $row['UserType'] . "&nbsp" . $row['FirstName'] . "</h3>"; 

         echo "<div class='post'></br> 
         <h3 class='title'>TODAY: Walk-In Clients</a></h3>"; 
         echo "<h4 class ='title'>" . date("F d, Y") . date(" (D)"); 
         echo "</h4></div>"; 

        //TableHeader 
         echo "<table border='1' cellpadding='5'> 
         <tr> 
         <th>Time In</th> 
         <th>Last Name</th> 
         <th>First Name</th> 
         <th>Middle Name</th> 
         <th>Promo Officer Name</th> 
         <th>Action</th> 
         </tr>";   

      /*------------------------------------------------------------ GoToDateTable ------------------------------------------------------------*/ 

        //GoToDate 

         echo " <link rel='stylesheet' type='text/css' media='all' href='jsDatePick_ltr.min.css' />"; 

         echo"<form name='sdate' action='#' method='post'>"; 
         echo"<input type='text' size='12' id='inputField' name='inputField1'>"; 
         echo"<a href='#' onclick='validateForm(document.forms['sdate'].action);return false;><img src='images/go.png' height='27' width='60'></a>"; 

        //GoToDateQuery 

         $result = mysql_query("SELECT TimeIn,LastName, FirstName, MiddleName ,PromoOfficerName FROM timein WHERE DateTrans='".$inputField1."'"); 


        //TableAlternateFieldColor     
         $sw = 0; 
         while($row = mysql_fetch_array($result)) 
          { 
            if($sw == 0) 
             { 
              $mycolor = "#fff"; 
              $sw = 1; 
             } 
            else 
             { 
              $mycolor = "#79b669"; 
              $sw = 0; 
             } 


        //TableRowAndTableData     
           echo "<tr bgcolor='".$mycolor."'>"; 
           echo "<td>" . $row['TimeIn'] . "</td>"; 
           echo "<td>" . $row['LastName'] . "</td>"; 
           echo "<td>" . $row['FirstName'] . "</td>"; 
           echo "<td>" . $row['MiddleName'] . "</td>"; 
           echo "<td>" . $row['PromoOfficerName'] . "</td>"; 
           echo "<td><image src='images/out.png' height=27 width=60></td>"; 
           echo "</tr>"; 
         } 

      /*------------------------------------------------------------ DateTodayTable ------------------------------------------------------------*/  

         $datetoday=date("m.d.Y"); 
         $result = mysql_query("SELECT TimeIn,LastName, FirstName, MiddleName ,PromoOfficerName FROM timein WHERE DateTrans='".$datetoday."'"); 

         $sw = 0; 
         while($row = mysql_fetch_array($result)) 
          { 
            if($sw == 0) 
             { 
              $mycolor = "#fff"; 
              $sw = 1; 
             } 
            else 
             { 
              $mycolor = "#79b669"; 
              $sw = 0; 
             } 
           echo "<tr bgcolor='".$mycolor."'>"; 

           echo "<td>" . $row['TimeIn'] . "</td>"; 
           echo "<td>" . $row['LastName'] . "</td>"; 
           echo "<td>" . $row['FirstName'] . "</td>"; 
           echo "<td>" . $row['MiddleName'] . "</td>"; 
           echo "<td>" . $row['PromoOfficerName'] . "</td>"; 
           echo "<td> <a href='#' onclick = PopupCenter('timeoutform.php?salesID=<?$row['PlanHoldersID']?>','myPop1',400,430)><image src='images/out.png' height=27 width=60> </a> </td>"; 
           echo "</tr>"; 
          } 
         echo "<a href='#' onclick = PopupCenter('timeinform.php','myPop1',400,430)> <img src = 'images/add.png' height='27' width='60'> </a>"; 
        } 

      /*------------------------------------------------------------ Administrator ------------------------------------------------------------*/     

        elseif ($type=="Administrator"){ 
         echo "<ul> 
           <li class='current_page_item'> <a href='#'>Home</a> </li> 
           <li> <a href='#'>Daily</a> </li> 
           <li> <a href='#'>Weekly</a> </li> 
           <li> <a href='#'>Commission</a> </li> 
           <li> <a href='#'>Client</a> </li> 
           </ul> </div>"; 

         echo " <br/><br/><h1 class='title'><a href='#'>Welcome</a></h1> 
         <div class='entry'>"; 
         echo "<h3>" . $row['UserType'] . "&nbsp" . $row['FirstName'] . "</h3>"; 

        } 
       ?> 

      </div> 

     </div> 
    </div> 
</div> 

<div id="footer-wrapper"> 
    <div id="footer"> 
     <p>Copyright (c) 2010 Sitename.com. All rights reserved. Design by FCT.</p> 
    </div> 
</div> 

</body> 

</html> 

问题1:

//GoToDate 

         echo " <link rel='stylesheet' type='text/css' media='all' href='jsDatePick_ltr.min.css' />"; 

         echo"<form name='sdate' action='#' method='post'>"; 
         echo"<input type='text' size='12' id='inputField' name='inputField1'>"; 
         echo"<a href='#' onclick='validateForm(document.forms['sdate'].action);return false;><img src='images/go.png' height='27' width='60'></a>"; 

这是一个文本框,它得到的日期,并触发查询来显示给定日期下的数据的按钮。手动输入日期时会出现问题,但在使用日期选择器时不起作用。

问题2:

echo "<td> <a href='#' onclick = PopupCenter('timeoutform.php?salesID=<?$row['PlanHoldersID']?>','myPop1',400,430)><image src='images/out.png' height=27 width=60> </a> </td>"; 
           echo "</tr>"; 

此按钮应显示timeoutform.php但它显示了FF。错误

Parse error: parse error, expecting T_STRING' or T_VARIABLE' or `T_NUM_STRING' in C:\wamp\www\IMS-MPP(Encoder)\home.php on line 209

希望有人可以帮忙。非常感谢!

+0

对于第二个问题,请尝试以下操作:echo“​​”;当然,这里存在安全风险。介意! – 2012-07-19 08:17:08

+0

首先解决所有错误消息。如果您在理解时遇到问题,请解释错误消息的哪一部分对您不清楚。 – hakre 2012-07-19 08:21:01

回答

1

“无需编写<?$row['PlanHoldersID']?>

更换”。$行[ 'PlanHoldersID'。”

echo "<td> <a href='#' onclick = PopupCenter('timeoutform.php?salesID=".$row['PlanHoldersID'].",'myPop1',400,430)><image src='images/out.png' height=27 width=60> </a> </td>"; 
+0

您可能想使用双引号来包装变量而不是单引号。 – Stegrex 2012-07-20 03:20:02

+0

谢谢你的回答:D – jamie 2012-07-20 03:39:01

1

对于问题2,你有一些靠不住的格式。尝试此:

echo "<td> <a href='#' onclick = PopupCenter('timeoutform.php?salesID=".$row['PlanHoldersID']."','myPop1',400,430)><image src='images/out.png' height=27 width=60> </a> </td>"; 

基本上,PHP被打印"<?$row['PlanHoldersID']?>"作为HTML内的字符串

+0

非常感谢你:)希望你能帮我解决problem1:D – jamie 2012-07-20 03:38:26

+0

@zeroSeven它看起来像datepicker是特定于jQuery。我会添加一些关于jQuery和Javascript的标签,让更多的人了解它可以帮助你。 – Stegrex 2012-07-20 03:56:24