Jump to content

get a specfic user details from mysql database using php?


jgkgopi

Recommended Posts

hi

i had database with field of name,title,post,content :rtfm:

 

i want to fetch the post and content for a specific user from giving name of that user by form help me to get that

 

ps just give me idea to how to do that/

 

<form id="form1" name="form1" method="post" action="view.php">
  <label>Name
  <input type="text" name="textfield" />
  </label>
  <p>
    <label>
    	<input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>

 

 

 

Link to comment
Share on other sites

Use something like this:

 

$username = $_POST['textfield'];
$query = "SELECT * FROM table_name WHERE userName=$username;

while($result == mysql_fetch_array($query)) {
//display
echo $result['title];
echo $result['post'];
echo $result['content'];
}

Link to comment
Share on other sites

 

 

$username = $_POST['textfield'];
$query = "SELECT * FROM table_name WHERE userName=$username;
while($result == mysql_fetch_array($query)) {
//display
echo $result['title];
echo $result['post'];
echo $result['content'];
}

 

where i have to use this code pls in the form

Link to comment
Share on other sites

You can use this code above ur form code

 

if(isset($_POST['Submit'])){
$username = $_POST['textfield'];
$query = mysql_query("SELECT * FROM table_name WHERE userName=$username");

while($result == mysql_fetch_array($query)) {
//display
echo $result['title];
echo $result['post'];
echo $result['content'];
}

}

Link to comment
Share on other sites

I have used this code

But it is in the same page

 

post title,content,conclusion are the column name used in my mysql datbase

 

this page is also view.php in action also am using view.php

<?php
//include 
if(isset($_POST['Submit'])){
$username = $_POST['textfield'];
$query = mysql_query("SELECT * FROM final WHERE name=$username");

while($result == mysql_fetch_array($query)) {
//display
echo $result['post title'];
echo $result['content'];
echo $result['conclusion'];
}
}
?>
<form id="form1" name="form1" method="post" action="view.php">
  <label>Name
  <input type="text" name="textfield" />
  </label>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>
  </p>
</form>

 

 

Link to comment
Share on other sites

Form code

<form id="form1" name="form1" method="post" action="v.php">
  <label>Name
  <input type="text" name="textfield" />
  </label>
  <p>
    <label>
    <input type="submit" name="Submit" value="Submit" />
    </label>

  </p>
</form>

 

PHP code

<?php 
mysql_connect("localhost","root",""); 
mysql_select_db("lasttry"); 
$username = $_POST['textfield'];
  echo '</br>';
$query = mysql_query("SELECT * FROM final WHERE name=`$username` ");

while($result = mysql_fetch_array($query)) {
//display
echo $result['content'];
echo $result['conclusion'];
}
?> 

 

Error getting on line 9

while($result = mysql_fetch_array($query)) {

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\wamp\www\mobile\v.php on line 9

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.