【问题标题】:PHP: How to retrieve data from mysql and insert to specific userPHP:如何从 mysql 检索数据并插入到特定用户
【发布时间】:2014-03-24 14:58:03
【问题描述】:

我将如何仅将以下数据插入特定用户。例如,来自用户名 Ben 和他的密码“cardboard”。

 <?php
      // Connects to your Database 
     mysql_connect("blank.blank.ac.uk", "", "") or die(mysql_error()); 
     mysql_select_db("dbBolives") or die(mysql_error()); 
     $data = mysql_query("SELECT * FROM bookings") 
     or die(mysql_error()); 
     Print "<table border cellpadding=3>"; 
     while($info = mysql_fetch_array( $data )) 
     { 
     Print "<tr>"; 
     Print "<th>id:</th> <td>".$info['id'] . "</td> "; 
     Print "<th>date:</th> <td>".$info['date'] . " </td></tr>"; 
     Print "<th>start:</th> <td>".$info['start'] . "</td> "; 
     Print "<th>name:</th> <td>".$info['name'] . " </td></tr>"; 
     Print "<th>email:</th> <td>".$info['email'] . "</td> "; 
     Print "<th>phone:</th> <td>".$info['phone'] . " </td></tr>"; 
     Print "<th>comments:</th> <td>".$info['comments'] . " </td></tr>"; 
     } 
     Print "</table>"; 

【问题讨论】:

    标签: php mysql database insert


    【解决方案1】:

    根据您的name 列,您可以使用WHERE 子句:

    ("SELECT * FROM bookings WHERE name='BOB'")
    

    举个例子。

    或者使用变量:

    $name = "BOB";
    

    然后做

    ("SELECT * FROM bookings WHERE name='$name'")
    

    【讨论】:

    • 不客气。我们现在可以关闭这个问题,因为它已经被回答了。只需单击白色(灰色轮廓)勾号/复选标记,直到它在我的答案中向上/向下箭头附近变为绿色,否则您的问题将保留在未回答的类别中。 @user3447225 这就是 SO 的工作原理 ;-)
    • read thissee this 了解接受答案的工作原理。 @user3447225 你发布了another question,但还没有关闭这个。请这样做是为了鼓励大家提供进一步的帮助。你可能还不知道 StackOverflow 是如何工作的,所以Take the tour
    猜你喜欢
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-09
    相关资源
    最近更新 更多