ckerr27 Posted March 27, 2012 Share Posted March 27, 2012 I have created a button which when pressed should present the user with their details (whoever is logged in), here is the form code: <form id="form1" name="form1" method="post" action="getdetails.php"> <input type="submit" name="Get Details" value="Get Details" /> </label> </p> </form> Here is the getdetails.php file <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $username = $_POST['textfield']; echo '</br>'; $query = mysql_query("SELECT * FROM membersdetails WHERE name=`$username` "); while($result = mysql_fetch_array($query)) { //display echo $result['firstname']; echo $result['surname']; } ?> Its not workin at all I have attacthed the error i am getting Any help please? Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/ Share on other sites More sharing options...
gristoi Posted March 27, 2012 Share Posted March 27, 2012 where are you declaring textfield in your form? Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1331578 Share on other sites More sharing options...
ckerr27 Posted March 27, 2012 Author Share Posted March 27, 2012 $username = $_POST['textfield']; What should be in here? Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1331586 Share on other sites More sharing options...
gristoi Posted March 27, 2012 Share Posted March 27, 2012 <form id="form1" name="form1" method="post" action="getdetails.php"> <input type="submit" name="Get Details" value="Get Details" /> </label> </p> </form> should be something like: <form id="form1" name="form1" method="post" action="getdetails.php"> username <input type="text" name="textfield" value ='' /> <input type="submit" name="Get Details" value="Get Details" /> </label> </p> </form> Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1331589 Share on other sites More sharing options...
ckerr27 Posted March 27, 2012 Author Share Posted March 27, 2012 Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\website\getdetails.php on line 8 This is the error im recieving now, although the form is better looking Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1331600 Share on other sites More sharing options...
litebearer Posted March 27, 2012 Share Posted March 27, 2012 use single quotes not backticks for your variables in you query Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1331614 Share on other sites More sharing options...
ckerr27 Posted March 29, 2012 Author Share Posted March 29, 2012 I have changed the quotes and still recieve the same error message. I think the error lies with this line $query = mysql_query("SELECT * FROM membersdetails WHERE name=`$username` "); Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1332274 Share on other sites More sharing options...
MSUK1 Posted March 29, 2012 Share Posted March 29, 2012 $query = mysql_query("SELECT * FROM membersdetails WHERE name=`$username` "); should be $query = mysql_query("SELECT * FROM membersdetails WHERE name='$username' "); you are still using backticks Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1332276 Share on other sites More sharing options...
ckerr27 Posted March 29, 2012 Author Share Posted March 29, 2012 <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $username = $_POST['textfield']; echo '</br>'; $query = mysql_query("SELECT * FROM memberdetails WHERE name='$username' "); while($result = mysql_fetch_array($query)) { //display echo $result['firstname']; echo $result['surname']; } ?> I think the error is on this line: while($result = mysql_fetch_array($query)) { i have attatched the error message to see if it helps Thanks Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1332361 Share on other sites More sharing options...
chriscloyd Posted March 30, 2012 Share Posted March 30, 2012 <?php mysql_connect("localhost","root",""); mysql_select_db("test"); $username = mysql_real_escape_string($_POST['textfield']); $query = mysql_query("SELECT * FROM memberdetails WHERE name = '{$username}' "); while($result = mysql_fetch_assoc($query)) { //display echo $result['firstname']; echo $result['surname']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259814-get-user-details-from-mysql-database-using-php/#findComment-1332559 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.