我想获得进行交易的会员的信息。在页面中,会员信息我只有会话的用户名$member_name = $_SESSION['member_name'];
<?php
include_once("config.php");
if(isset($_SESSION["products"])) {
$member_name = $_SESSION['member_name'];
$total = 0;
echo '<form action="cart-post-config.php" enctype="multipart/form-data" method="POST">';
foreach ($_SESSION["products"] as $cart_itm) {
echo '<tr>';
echo '<td></td>';
<!---- THIS IS WHERE I PUT THE INFO OF USERNAME ---->
echo '<input type="hidden" name="member_name" value="'.$member_name.'"/>';
echo '<td><input type="text" readonly name="product_name[]" value="'.$cart_itm["name"].'"/></td>';
echo '<td><input type="text" readonly name="product_price[]" value="'.$cart_itm["price"].'"/></td>';
echo '<td><input type="text" readonly name="product_quantity[]" value="'.$cart_itm["qty"].'"/></td>';
$totalPerEach = ($cart_itm["price"]*$cart_itm["qty"]);
echo '<td><input type="text" readonly name="product_eachTotal[]" value="'.$totalPerEach.'"/></td>';
echo '<td>View Save Delete</td>';
echo '</tr>';
}
在SESSION of Products的回声中,我想获得会员的更多详细信息,例如地址,密码等。
echo ' <!---- THIS IS WHERE I WANT TO WRITE SQL SELECT STATEMENT ---->
<div id="process-to-detail">
<div id="user-information">
<table>
<tr>
<td>Your Name is</td>
<td>Your Address is</td>
<td>Your Phone is</td>
</tr>
</table>
</div>
</div>';
在echo里面的注释中,我想编写一个sql语句来获取成员的更多细节,点是select * from member_list where member_name=$_SESSION['member_name'];
请告诉我是否可以在echo&#39; ...&#39;;如果不是,如何获取会员详细信息。
非常感谢。
答案 0 :(得分:2)
将您尝试在函数中引入的功能包装起来然后调用它。
实施例
function getMyUserData($member_name) {
$myUserDataString = false; // Default value.
// your database connectivity
$dbconn = new mysqli('server','user','password','database');
// Sanitize your input to avoid SQL injection issues.
$member_name = $dbconn->real_escape_string($member_name);
// your sql statement
//It would be better to use a unique id instead of a name.
$sql = "SELECT `password`, `address` FROM `USERS` WHERE " .
"`member_name` = '$member_name' LIMIT 1";
// execute query
$result = $dbconn->query($sql);
// check for query result
if(is_object($result) && $result->num_rows > 0) {
// Get data from result.
$myUserData = $result->fetch_assoc();
// Free the result
$result->free;
// Access the fields you wanted
$myUserDataString = "My user address: " . htmlentities($myUserData['address']);
//You may echo the string here to cause the function to output your text
// or return the value and echo it. In this case we will return the value.
}
return $myUserDataString;
}
echo getMyUserData($_SESSION['member_name']);
我希望这有帮助..
P.S。将密码返回给客户端通常不是一个好主意。尝试使用哈希或加密进行单向加密。
有关详细信息,请参阅以下链接: