jgkgopi Posted May 2, 2011 Share Posted May 2, 2011 hi i had database with field of name,title,post,content 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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/ Share on other sites More sharing options...
spiderwell Posted May 2, 2011 Share Posted May 2, 2011 "SELECT `post`, `content` from `table` where `name` = ' " . $_POST['textfield'] . ";"; Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209310 Share on other sites More sharing options...
kney Posted May 2, 2011 Share Posted May 2, 2011 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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209314 Share on other sites More sharing options...
jgkgopi Posted May 2, 2011 Author Share Posted May 2, 2011 $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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209333 Share on other sites More sharing options...
kney Posted May 2, 2011 Share Posted May 2, 2011 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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209336 Share on other sites More sharing options...
jgkgopi Posted May 2, 2011 Author Share Posted May 2, 2011 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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209419 Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 while($result == mysql_fetch_array($query)) { You should be using the assignment operator (=) there. Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209435 Share on other sites More sharing options...
kney Posted May 2, 2011 Share Posted May 2, 2011 ur right .. lol, sorry Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209437 Share on other sites More sharing options...
jgkgopi Posted May 2, 2011 Author Share Posted May 2, 2011 have changed like this while($result = mysql_fetch_array($query)) { still it is in the same page, i want to get the user from me and show the details of that particular user Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209466 Share on other sites More sharing options...
wildteen88 Posted May 2, 2011 Share Posted May 2, 2011 Your query is constructed incorrectly $query = mysql_query("SELECT * FROM final WHERE name=$username"); $username needs to be wrapped in single quotes. Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209470 Share on other sites More sharing options...
jgkgopi Posted May 3, 2011 Author Share Posted May 3, 2011 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 https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209809 Share on other sites More sharing options...
spiderwell Posted May 3, 2011 Share Posted May 3, 2011 wrong quotes my friend, you have back ticks ```````````` around a value and you need single quotes ' ' ' ' ' ' ', backticks are used around column names or table names "SELECT * FROM `final` WHERE `name`='$username' then you should be ok Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1209810 Share on other sites More sharing options...
jgkgopi Posted May 7, 2011 Author Share Posted May 7, 2011 thank you got it Link to comment https://forums.phpfreaks.com/topic/235326-get-a-specfic-user-details-from-mysql-database-using-php/#findComment-1211984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.