PHP:如何从mysql中检索数据并插入特定用户

时间:2014-03-24 14:58:03

标签: php mysql database insert

我如何将以下数据仅插入特定用户。例如,从用户名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>"; 

1 个答案:

答案 0 :(得分:0)

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

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

作为一个例子。

或使用变量:

$name = "BOB";

然后做

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