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

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

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

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

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.