dongzeao5047 2015-07-11 02:12
浏览 201

以bootstrap模式形式显示数据库中的数据(PHP MySQL)

I am new to both bootstrap and php. I have created a registration modal form to register users for my site and it registers perfectly. However, I would like to retrieve a users details from my database based on their User ID and display their details in a registration form for them to edit and update. What I don't know how to do is display the records in the form fields... Please help by providing a simple syntax for this.

I am using PHP and MySql

This is my modal form

<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>

I dont know how to include the php in this form as it disappears Also if you could include links for further reading on php I would really appreciate.

  • 写回答

1条回答 默认 最新

  • douwuli4512 2015-07-11 02:20
    关注

    Without seeing any code it's difficult to give more specific help. However, what I would do is store the user's id in a session. When they view the form brab the id from the session and do a SQL call to your db, something like:

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

    Obviously what you select, the table_name, and the where clause depends on your own tables and variables.

    Run your SQL command and store the columns into variables. Then place the variable into the value of the input:

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

    Basically, what I did above is a shorthand if statement that says if $name isn't blank they print it, otherwise print nothing.

    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答