Jump to content

Show specific members details


ckerr27

Recommended Posts

Hey i have created the code below attempting to show a specific members details when their username is entered and the submit button is pressed. but when i enter the username all members details are shown. The code i have used is shown below, can anybody help me with the code to just show the single users details. I have attached an image aswell.

 

<?php

mysql_connect ("localhost","root","");

mysql_select_db ("test");

 

$sql = "select * from memberdetails";

      $result = mysql_query ($sql);

 

      while ($row = mysql_fetch_array($result))

              {

              $username= $row["username"];

              $firstname= $row["firstname"];

          $surname= $row["surname"];

              $dob= $row["dob"];

              $totalwins= $row["totalwins"];

              $totalloses= $row["totalloses"];

              $email= $row["email"];

              $country= $row["country"];

              $info= $row["info"];

 

             

 

echo "<b><u>Username:</b></u>  $username<br>";

echo "<b><u>Firstname:</b></u> $firstname<br>";

echo "<b><u>Surname: </b> </u> $surname<br>";

echo "<b><u>Date of Birth:</b></u> $dob<br>";

echo "<b><u>Total Chess Wins:</b></u>  $totalwins<br>";

echo "<b><u>Total Chess loses:</b></u> $totalloses<br>";

echo "<b><u>Email Address: </b></u> $email<br>";

echo "<b><u>Born in: </b></u> $country<br>";

echo "<b><u>Other Details:</b></u>  $info<br>";

          }

?>

post-131533-13482403366433_thumb.jpg

Link to comment
Share on other sites

if(isset($_POST['searchname'])){
$inputName = mysql_real_escape_string($_POST['searchname']);
}else{
$inputName='';
}
$sql = "select * from memberdetails WHERE username = $inputName";

 

This is assuming you have a form that take the search input. Replace 'searchname' with whatever you have named the text box on your input form.

Link to comment
Share on other sites

$username = "kerr1234";

$sql = sprintf("select * from memberdetails where username = '%s' ",$username);

 

This code will only return kerr1234 details , is there anything i can add to make it show the details or which ever member the user types?

Link to comment
Share on other sites

Do you mean as so:

 

if(isset($_POST['searchname'])){

$inputName = mysql_real_escape_string($_POST['searchname']);

}else{

$inputName='';

}

$sql = "select * from memberdetails WHERE username = $inputName";

     

$result = mysql_query ($sql);

 

      while ($row = mysql_fetch_array($result))

 

 

This is giving me an error on the last line of code

Link to comment
Share on other sites

Sorry, I think I missed some single quotes in there. I mean to put your original one back in:

 

$sql = sprintf("select * from memberdetails where username = '%s' ",$inputName);

 

Are you familiar with capturing input with an HTML for and passing that information to a PHP script? You should have a form with a text box name something like 'inputName' that you can catch with a POST on your script, then insert that into your SQL query.

Link to comment
Share on other sites

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

 

This is the form i use, is this ok?

Link to comment
Share on other sites

echo "<b><u>Username:</b></u>  $username<br>";

echo "<b><u>Firstname:</b></u> $firstname<br>";

echo "<b><u>Surname: </b> </u> $surname<br>";

echo "<b><u>Date of Birth:</b></u> $dob<br>";

echo "<b><u>Total Chess Wins:</b></u>  $totalwins<br>";

echo "<b><u>Total Chess loses:</b></u> $totalloses<br>";

echo "<b><u>Email Address: </b></u> $email<br>";

echo "<b><u>Born in: </b></u> $country<br>";

echo "<b><u>Other Details:</b></u>  $info<br>";

          }

?>

 

I use the above code to echo but when i enter the username into the form and press the button i get an empty page

Link to comment
Share on other sites

Just because you've written code to show information, it doesn't mean it will. There are various problems which could arise such as no results being returned from your query...

 

Ensure you're getting the expected results by dumping the information; if not there may be something wrong with your input. Work out the problem and go through your script piece by piece killing it at certain points to ensure its getting past specific if statements etc.

 

You can also set your error reporting to all using the error_reporting(-1) at the top of your script.

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.