Jump to content

get user details from mysql database using php?


ckerr27

Recommended Posts

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?

post-131533-13482403357394_thumb.jpg

Link to comment
Share on other sites

<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>

Link to comment
Share on other sites

<?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

post-131533-13482403362186_thumb.jpg

Link to comment
Share on other sites

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

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.