2013-03-22 77 views
1

有人請幫忙!這可能是一個非常簡單的錯誤,但我是PHP & MySQL的新手。我試圖根據用戶的日期選擇從數據庫中檢索信息。我使用了一些在YouTube上找到的例子,用jquery將輸入發佈到php頁面,並在html頁面上顯示來自php的檢索值。但是,它似乎只返回下面的else if語句。非常感謝您的幫助!

的Html下面:

<div id="customDateRange"> 
    <h2>Welcome <?php echo $companyName ?></h2> 
    <h3 style="color:#ff0000">This is currently under development</h3> 
    <h4>Please specify the dates you would like to view below:</h4> 
    <label for="dateStart">Start Date</label> 
    <input class="datePick" id="dateStart" name="dateStart" type="text"/> 
    <label for="dateEnd">End Date</label> 
    <input class="datePick" ud="dateEnd" type="text"/> 
    <input id="getDateRange" type="submit" value="Display Report" /> 
    <div id="fromDatabase"></div> 
</div> 

的Javascript下面:

$('.datePick').datepicker({ minDate: new Date(2013, 3 - 1, 1), dateFormat: 'yy-mm-dd' }); 

$('input#getDateRange').on('click', function(){ 
    var startDate = $('input#dateStart').val(); 
    if ($.trim(startDate) != '') { 
     $.post('../../includes/dateRangeDB.php', function(data, status){ 
      $('div#fromDatabase').text(data); 
     }); 
    } 
}); 

PHP下面:

<?php 
if (isset($_POST['dateStart']) === true && empty($_post['dateStart']) === false) { 
    $query = mysql_query(" 
     SELECT TotalCost FROM adwords_reporting WHERE CampaignID = 'CAMP020' AND Date IN ('" . mysql_real_escape_string(trim($_POST['dateStart'])) . "') 
    "); 

    echo "Total Cost: " . (mysql_num_rows($query) !== 0) ? mysql_result($query, 0, 'TotalCost') : 'Date Not Found'; 
} 
else if (isset($_POST['dateStart']) === false) { 
    echo "WTF MAN!"; 
} 
else { 
    echo "It seems there is an issue"; 
} 
?> 

謝謝您的幫助!

+1

建議。如果您有元素ID,請不要在其之前添加標籤名稱。 '$(「#getDateRange」)。在(...' – 2013-03-22 21:04:41

+0

它看起來並不像你加入後變量到$ .post的電話。這個問題是jQuery的帖子...你應該重提到文檔 – rnirnber 2013-03-22 21:07:24

+0

@RicardoLohmann謝謝,我應該知道比包含標籤名稱更好* smh * – soulglow1985 2013-03-25 16:10:57

回答

3

您需要實際發送日期:

$('input#getDateRange').on('click', function(){ 
    var startDate = $('input#dateStart').val(); 
    if ($.trim(startDate) != '') { 
     $.post('../../includes/dateRangeDB.php', {dateStart: startDate}, function(data){ 
      $('div#fromDatabase').text(data); 
     }); 
    } 
}); 

到能夠訪問它:

$_POST['dateStart']