PHP:如何从mysql检索数据并插入特定用户(PHP: How to retrieve data from mysql and insert to specific user)

编程入门 行业动态 更新时间:2024-10-24 06:39:04
PHP:如何从mysql检索数据并插入特定用户(PHP: How to retrieve data from mysql and insert to specific user)

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

How would i go about inserting the data below to a specific user only. for example, from the username Ben and his password "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>";

最满意答案

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

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

举个例子。

或者使用变量:

$name = "BOB";

然后做

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

Based on your name column, you could use a WHERE clause:

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

as an example.

Or use a variable:

$name = "BOB";

then do

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

更多推荐

Print,$info,th>,<td>,电脑培训,计算机培训,IT培训"/> <meta name="

本文发布于:2023-07-04 16:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1026882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   用户   PHP   mysql   retrieve

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!