Sunday 15 April 2012

php - Sql SELECT statement inside echo -



php - Sql SELECT statement inside echo -

i want info of fellow member transaction. in page, fellow member info have username session such $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"] $cart_itm) { echo '<tr>'; echo '<td></td>'; <!---- set 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>'; }

inside echo of session of products, want farther detail info of member, such address, password , etc.

echo ' <!---- want 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>';

in comment above within echo, want write sql statement farther detail of fellow member point select * member_list member_name=$_session['member_name'];

please tell me possible create sql statement within echo '...'; if not, how fellow member detail info.

many thanks.

wrap functionality you're trying introduce in function , phone call it.

example

function getmyuserdata($member_name) { $myuserdatastring = false; // default value. // database connectivity $dbconn = new mysqli('server','user','password','database'); // sanitize input avoid sql injection issues. $member_name = $dbconn->real_escape_string($member_name); // sql statement //it improve utilize unique id instead of name. $sql = "select `password`, `address` `users` " . "`member_name` = '$member_name' limit 1"; // execute query $result = $dbconn->query($sql); // check query result if(is_object($result) && $result->num_rows > 0) { // info result. $myuserdata = $result->fetch_assoc(); // free result $result->free; // access fields wanted $myuserdatastring = "my user address: " . htmlentities($myuserdata['address']); //you may echo string here cause function output text // or homecoming value , echo it. in case homecoming value. } homecoming $myuserdatastring; } echo getmyuserdata($_session['member_name']);

i hope helps..

p.s. it's not thought homecoming password client. seek using hash or crypt 1 way encryption.

see next links details:

http://php.net/manual/en/function.crypt.php http://php.net/manual/en/function.hash.php

php mysql session

No comments:

Post a Comment