Jump to content

Reading Individual Record From Mysql


arjunking

Recommended Posts

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 by arjunking
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.