dsgdhtr_43654 2014-06-27 15:14 采纳率: 100%
浏览 35

如何在特定于用户的数据库中输出信息

I have been teaching myself code for the past 3 months now and I am working on a project that is outside my level of knowledge. So on the site we're creating, we have a page where the user creates a profile and anyone who visits the site see's that information, the information they input is stored in a database table. What I am trying to do is only display that information for that specific user. Right now I have created three different users and when I login to each one it displays the same information for each user. I am sure this question has been answered i just dont know how to word it. Below is the input form and .php file i am currently using.

<div class="modal-body">
                          <form action="edit_profile.php" method="post">
                        <input type="text" class="form-control" id="exampleInputEmail1" placeholder="Name" name="name" required="">
                          <br>
                        <textarea class="form-control" name="about_me" rows="3" placeholder="About Me (300 Characters Max)"></textarea></textarea>
                          <br>
                        <input type="text" class="form-control" id="exampleInputEmail" placeholder="My Specialties" name="specialty" required="">
                          <br>
                        <input type="text" class="form-control" id="exampleInputEmail" placeholder="City" name="city" required="">
                          <br>
                        <input type="text" class="form-control" id="exampleInputEmail" placeholder="State" name="state" required="">
                          <br>
                        <input type="email" class="form-control" id="exampleInputEmail" placeholder="Email" name="email" required="">
                          <br>
                        <input type="text" class="form-control" id="exampleInputEmail" placeholder="Website" name="website" required="">
                          <br>
                        <input type="email" class="form-control" id="exampleInputEmail" name="facebook" placeholder="Facebook Link">
                          <br>
                        <input type="email" class="form-control" id="exampleInputEmail" name="instagram" placeholder="Instagram Link">
                          <br>
                        <input type="email" class="form-control" id="exampleInputEmail" name="twitter" placeholder="Twitter Link">
                          <br>
                        <input type="email" class="form-control" id="exampleInputEmail" name="google" placeholder="Google+ Link">
                          <br>
                        <input type="submit" class="btn btn-primary" value="submit">
                        <button type="button" class="btn btn-default"  data-dismiss="modal">Close</button>
                        </form>
                      </div>
                    </div>
                  </div>
                </div>
            <!-- End Edit Profile Modal -->

            <h4><strong>About Me: </strong></h4>
                <?php echo $row['about_me'];?>
            <h4><strong>My Specialties: </strong></h4>
                <?php echo $row['specialty'];?>
            <h4><strong>Location: </strong> </h4>
                <?php echo $row['city'];?>, <?php echo $row['state'];?>
            <h4><strong>Get Connected: </strong></h4>
                <h5><strong>Email:</strong> <?php echo $row['email'];?> </h5>
                <h5><strong>Website:</strong> <?php echo $row['website'];?></h5>
                <h5><strong>Facebook:</strong> <?php echo $row['facebook'];?></h5>

//DATABASE CONNECT
<?php
$host="localhost";
$username="XXXXXXX";
$password="XXXXXXX";
$db_name="photographer_directory";
$tbl_name="qls3_profile";

mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

$result = mysql_query("SELECT * FROM qls3_profile");

$row = mysql_fetch_array($result);
?>

<?php

include_once('includes/db_connect.php');

$name=$_POST['name'];
$about_me=$_POST['about_me'];
$specialty=$_POST['specialty'];
$city=$_POST['city'];
$state=$_POST['state'];
$email=$_POST['email'];
$website=$_POST['website'];
$facebook=$_POST['facebook'];
$instagram=$_POST['instagram'];
$twitter=$_POST['twitter'];
$google=$_POST['google'];

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(name, about_me, specialty, city, state, email, website, facebook,   instagram, twitter, google)VALUES('$name', '$about_me', '$specialty', '$city', '$state', '$email',  '$website', '$facebook', '$instagram', '$twitter', '$google')";
$result=mysql_query($sql);

// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}

else {
echo "ERROR";
}

header( 'Location: userprofile.php' ) ;
?>

<?php 
// close connection 
mysql_close();
?>
  • 写回答

1条回答 默认 最新

  • dongwen7187 2014-06-27 15:17
    关注

    You want to use a SQL SELECT ... FROM ... WHERE clause. It is best if you learn if for yourself: http://www.w3schools.com/sql/sql_where.asp

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法