2017-04-04 56 views
-3

我在這裏顯示2代數據庫表的工作,即1是從chapter_subscription table.In chapter_subscription表顯示10章分配所輸入的用戶輸入用戶信息用戶的信息顯示另一個之後有下拉沒有在PHP

  1. 章節編號字段
  2. 開始日期
  3. 結束日期

我的目標是創建下拉選項,結束日期,讓用戶可以從下拉列表中選擇它。但我的問題是我使用了選項標籤,當我運行它是告訴意外的loop.Please可以幫助解決這個錯誤,並讓我顯示每個顯示的結束日期下拉。因爲我是PHP的新手,請提前感謝您。 insert_dummy.php

<?php 

    include('db.php'); 




    $userName=mysql_real_escape_string($_POST['userName']); 



    $userEmail=mysql_real_escape_string($_POST['userEmail']); 
    $userPassword=mysql_real_escape_string($_POST['userPassword']); 
    $expiry_date1=mysql_real_escape_string($_POST['expiry_date']); 
    $expiry_date=date("Y-m-d" ,strtotime($expiry_date1)); 
    $end_date1=mysql_real_escape_string($_POST['end_date']); 
    $end_date=date("Y-m-d",strtotime($end_date1)); 



    $regDate = date("Y-m-d"); 



    function generateCode($characters) 
    { 
     $possible = '[email protected]#$%^&*'; 
     $code = ''; 
     $i = 0; 
     while ($i < $characters) { 
      $code .= substr($possible, mt_rand(0, strlen($possible)-1), 1); 
      $i++; 
     } 
     return $code; 
    } 

    $registration_key=generateCode(10); 



    $str="insert into coeds_user(userName,userEmail,userPassword,regDate,expiry_date,registration_key) values('$userName','$userEmail','$userPassword','$regDate','$expiry_date','$registration_key')"; 


    $query=mysql_query($str); 
    $userid=mysql_insert_id(); 
    if($query) 
    { 
    $display="Success"; 
    } 
    else 
    { 
    $display= "Failed"; 
    } 
    $string="select * from coeds_user where userId=$userid"; 
    $query2=mysql_query($string); 
    $display.="<table border='1' align='center'>"; 
    $display.="<tr><th>UserName</th><th>UserEmail</th><th>UserPassword</th><th>RegDate</th><th>ExpiryDate</th><th>RegistrationKey</th><th colspan='3'>Action</th></tr>"; 
    while($result=mysql_fetch_array($query2)) 
    { 
    $display.="<tr>"; 

    $display.="<td>".$result['userName']."</td>"; 
    $display.="<td>".$result['userEmail']."</td>"; 
    $display.="<td>".$result['userPassword']."</td>"; 
    $display.="<td>".$result['regDate']."</td>"; 
    $display.="<td>".$result['expiry_date']."</td>"; 
    $display.="<td>".$result['registration_key']."</td>"; 
    $display.="<td><a id='colour' class='tooltip' title='Edit' href='user_update.php?user_Id=".$result['userId']."'><img id='image' src='./images/small.gif'/></a></td>"; 
    $display.="<td><a id='colour' class='tooltip' data-toggle='tooltip' title='Delete' href='user_delete.php?user_Id=".$result['userId']." '><img id='image' src='./images/trash.png'/></a></td>"; 



    $display.="</table>"; 
    $end_date1 = date('Y-m-d', strtotime("+1 months")); 
    $end_date2 = date('Y-m-d', strtotime("+3 months")); 
    $end_date3 = date('Y-m-d', strtotime("+6 months")); 
    $end_date4 = date('Y-m-d', strtotime("+9 months")); 
    $end_date5 = date('Y-m-d', strtotime("+12 months")); 
    $page=""; 


    $str="select chapter_no from chapter_details "; 


    $query7=mysql_query($str); 

    $count=mysql_num_rows($query7); 
    for($i=0;$i<$count;$i++) 
    { 
    $chap_lic=generateCode(50); 
    $chapter_no=mysql_result($query7,$i,'chapter_no'); 
    $start_date=date('Y-m-d'); 
    $expiry_date=mysql_real_escape_string($_POST['end_date']); 
    $end_date=date("Y-m-d" ,strtotime("+3 months")); 
    /*$end_date1=mysql_real_escape_string($_POST['end_date']); 
    $end_date=date("Y-m-d",strtotime($end_date1));*/ 
    $s="insert into chapter_subscriptions (userId,chapter_no,start_date,end_date) values($userid,$chapter_no,'$start_date','$end_date')"; 
    $end_date=date("Y-m-d" ,strtotime("+3 months")); 

    $query8=mysql_query($s); 
    } 
    $strings="select * from chapter_subscriptions where userId=$userid"; 
    $query9=mysql_query($strings); 
    $display.="<table border='1' align='center'>"; 
    $display.="<tr><th>ChapterNumber</th><th>StartDate</th><th>EndDate</th><th colspan='2'>Action</th></tr>"; 
    while($result=mysql_fetch_array($query9)) 
    { 
    $display.="<tr>"; 
    $display.="<td>".$result['chapter_no']."</td>"; 
    $display.="<td>".$result['start_date']."</td>"; 


    $display.="<tr><select>".$result['end_date']. 
    for($i=0;$i<5;$i++) 
    { 
    $display.="<td><option value=echo $end_date1;>echo $end_date1;</option></td>"; 
    $display.="<td><option value=echo $end_date2;>echo $end_date2;</option></td>"; 
    $display.="<td><option value=echo $end_date3;>echo $end_date3;</option></td>"; 
    $display.="<td><option value=echo $end_date4;>echo $end_date4;</option></td>"; 
    $display.="<td><option value=echo $end_date5;>echo $end_date5;</option></td>"; 

    } 
    $display.="</select></tr>" 
    $display.="<td><a id='colour' class='tooltip' title='Edit' href='chapter_subscription_update.php?user_Id=".$result['userId']."'><img id='image' src='./images/small.gif'/></a></td>"; 
    $display.="<td><a id='colour' class='tooltip' data-toggle='tooltip' title='Delete' href='chapter_subscription_delete.php?user_Id=".$result['userId']." '><img id='image' src='./images/trash.png'/></a></td>"; 

    $display.="</tr>"; 
    } 
    $display.="</table>"; 
    ?> 
+0

** **停止使用廢棄的'mysql_ *'API。使用mysqli_ *'或'PDO' – Jens

+0

檢查錯誤執行SQL語句 – Jens

+0

在SQL查詢 – Vradhit

回答

0

瞭解如何調試代碼!檢查How to get useful error messages in PHP?以瞭解如何啓用詳細錯誤。我還建議你檢查this handy guide常見的錯誤。並使用檢查常見錯誤的IDE,或使用在線code validator。堆棧溢出不是一個獲取調試幫助的地方,請查詢What topics can I ask about here?,以獲取有關您可以在此處詢問的更多信息。


1)你有沒有分號(的for循環導致該錯誤之前的線):

$display.="<tr><select>".$result['end_date']. 

這應該是這樣的:

$display.="<tr><select>".$result['end_date']; 

2 )您有一段時間不會關閉的循環(在腳本的某處丟失}):

while($result=mysql_fetch_array($query2)) { 

3)和...

$display.="</select></tr>" 

應該

$display.="</select></tr>"; 
+0

沒有錯誤我糾正之後,但現在它告訴,在管線227 – Vradhit

+0

$顯示意想不到的$顯示。=「​​」 ; – Vradhit

+0

@Vradhit檢查編輯,你忘了另一個分號。 –