2015-07-11 77 views
0

我是bootstrap和php的新手。我創建了一個註冊模式表單來爲我的網站註冊用戶,並完全註冊。但是,我想根據用戶ID從我的數據庫中檢索用戶詳細信息,並在註冊表單中顯示其詳細信息以供他們編輯和更新。 我不知道該怎麼做是在表單域中顯示記錄... 請爲此提供一個簡單的語法來提供幫助。以引導模式形式(PHP和MySQL)顯示數據庫中的數據

我使用PHP和MySQL

這是我的模態形式

<div class="modal fade" id="updatelecModal" tabindex="-1" role="dialog" aria-labelledby="updatelecModalLabel" aria-hidden="true"> 
     <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
      </div> 
      <div class="modal-body"> 
      <!--End of modal--> 

      <!-- Start of form--> 

      <form id="updatelecForm" class="form-horizontal" role="form" method="post" action="#" nonvalidate> 
       <div class="form-group"> 
        <label for="student_id" class="col-sm-3 control-label">Lecturer ID</label> 
        <div class="col-lg-9"> 
        <input type="text" class="form-control" name="lec_id" required placeholder="Enter User ID"> 
        </div> 
       </div> 

       <div class="form-group"> 
        <label class="col-lg-3 control-label">Full name</label> 
        <div class="col-lg-4"> 
         <input type="text" class="form-control" name="firstName" required placeholder="First name" /> 
        </div> 
        <div class="col-lg-4"> 
         <input type="text" class="form-control" name="lastName" required placeholder="Last name" /> 
        </div> 
       </div> 
       <div class="form-group"> 
        <label for="email" class="col-sm-3 control-label">Email</label> 
        <div class="col-lg-9"> 
        <input type="email" class="form-control" name="lec_email" required placeholder="####@##.com"> 
        </div> 
       </div> 
        <label class="col-xs-3 control-label" name="lec_gender">Gender:</label> 

        <label class="radio-inline control-label"> 
         <input type="radio" name="optionsRadio" id="gender" value="Male">Male 
        </label> 

        <label class="radio-inline control-label"> 
         <input type="radio" name="optionsRadio" id="gender" value="Female">Female 
        </label> 

        <div class="form-group"> 
        <label for="password" class="col-sm-3 control-label">Password</label> 
        <div class="col-sm-7"> 
        <input type="password" id="password" class="form-control" name="password" required placeholder ="Enter your Password"> 
        </div> 
       </div> 
       <div class="form-group"> 
        <label for="password" class="col-sm-3 control-label">Confirm Password</label> 
        <div class="col-sm-7"> 
        <input type="password" id="password2" class="form-control" name="cpassword" data-validate-linked="password" required placeholder ="Re-enter your Password"> 
        </div> 
       </div> 
       <div class="modal-footer"> 
        <button type="submit" class="btn btn-primary">Register</button> 
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> 
        <button type="reset" class="btn btn-default">Reset</button> 
       </div> 
       </form> 

        <!--End of registration form--> 
      </div> 
     </div> 
     </div> 
    </div> 

我不知道如何將這種形式的PHP的,因爲它消失 此外,如果你可以包括進一步閱讀PHP的鏈接,我真的很感激。

回答

0

沒有看到任何代碼,很難給出更具體的幫助。但是,我要做的是將用戶的ID存儲在session中。當他們查看brab從session該ID的形式,做一個SQL調用你的數據庫,是這樣的:

SELECT firstName,lastName,email, FROM table_name WHERE id=$id 

顯然,你選擇什麼樣的table_name和where子句取決於你自己的表和變量。

運行您的SQL命令並將列存儲到變量中。然後把變量到輸入的值:

<input type="text" value="<?php echo $name != '' ? $name : ''; ?>" /> 

基本上,我上面所做的是一個速記if語句說,如果$名稱不是空白,他們打印出來,否則打印什麼。

+0

謝謝,我得到了正確的SQL,但我有問題的PHP。我應該將它作爲外部文件編寫還是寫入與表單相同的文件? –