arjunking Posted October 26, 2012 Share Posted October 26, 2012 (edited) Hi i have set up a blog based on wordpress. I want to add data which is read-only for the users. So i created two fields : user_a and user_b Now i want the users to be able to read the data . I dont know how to use session function so i created a page which asks for the user_id and user_pass and returns the field user_survey and user_survey_complete Instead of returning the data in user_survey and user_survey_complete , it just returns the heading user_survey and user_survey_complete the code which asks for data is : <form id="FormName" action="surveycheck.php" method="post" name="FormName"> <table width="448" border="0" cellspacing="2" cellpadding="0"> <tr> <td width="150" align="right"><label for="user_id">Username</label></td> <td><input name="user_id" maxlength="32" type="text" value="<?php echo stripslashes($user_id) ?>"></td> </tr> <tr> <td width="150" align="right"><label for="user_pass">Password</label></td> <td><input name="user_pass" maxlength="32" type="text" value="<?php echo stripslashes($user_pass) ?>"></td> </tr> <tr> <td colspan="2" align="center"><input name="" type="submit" ></td> </tr> </table> </form> The code which I used to display the data <html><head><title>MySQL Table Viewer</title></head><body> <?php $db_host = 'localhost'; $db_user = 'userid'; $db_pwd = 'password'; $database = 'wordpress_management'; $table = 'wp_users'; $user_id = trim(mysql_real_escape_string($_POST["user_id"])); $user_pass = trim(mysql_real_escape_string($_POST["user_pass"])); if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // sending query $result = mysql_query("SELECT user_survey_link, user_survey_compelete FROM {$table} WHERE {$user_id}=user_login AND {$user_pass}=user_pass "); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo "<h1>Table: {$table}</h1>"; echo "<table border='1'><tr>"; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } mysql_free_result($result); ?> </body></html> Please help me in displaying the data under the fields. If someone know wordpress then please help me use session instead of asking for userid and pass I am a noob and not good at php so please provide the solution in detail Thanks a lot Edited October 26, 2012 by arjunking Quote Link to comment https://forums.phpfreaks.com/topic/269948-reading-individual-record-from-mysql/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.