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>

 

 

 

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'];
}

 

 

$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

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'];
}

}

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>

 

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.