hi i need some help someone please. i tried so many combinations of code with but not getting anywhere. I need a user to enter an id through a form, then the code should retrieve certain fields of the table and display them in a table. here is the code.

<form method="POST" action="actioned.php">
<table>
<col span="1" align="right">
<tr>
<td><font color="blue">Membership No:</font></td>
<td><input type="text" name="id" id="id" size=50></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>


<?php 
// Connects to your Database 
$dbhost = "localhost";  // variable holding host information
$dbname = "sportscentre";  // variable holding the name of the database
$dbuser = "*****";  // variable holding the username of the person using database account
$dbpass = "*****";  // variable holding password of the person using database account

$connection = mysql_connect($dbhost, $dbuser, $dbpass)or die("Cannot connect");

$connection = mysql_select_db($dbname)or die("cannot select DB");

$id = $_POST['id']; 

$data = mysql_query("SELECT title, first_name, surname, addr_line_1, addr_line_2, city, postcode, tel_number, mob_number, email FROM members where id = '$_post[id]'")or die(mysql_error());
$result = mysql_query($data)or die ("Query failed: " . mysql_error());
 
Print "<table border cellpadding=3>"; 
while($info = mysql_fetch_array( $data )) 
{ 
Print "<tr>"; 
Print "<th>Title:</th><td>".$info['title'] . "</td></tr>";
Print "<tr>";
Print "<th>First Name:</th> <td>".$info['first_name'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Surname:</th> <td>".$info['surname'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Address Line 1:</th> <td>".$info['addr_line_1'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Address Line 2:</th> <td>".$info['addr_line_1'] . " </td></tr>"; 
Print "<tr>";
Print "<th>City:</th> <td>".$info['city'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Postcode:</th> <td>".$info['postcode'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Tel Number:</th> <td>".$info['tel_number'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Mob Number:</th> <td>".$info['mob_number'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Email:</th> <td>".$info['email'] . " </td></tr>"; 
//Print "<tr>";
//Print "<th>Username:</th> <td>".$info['username'] . " </td></tr>"; 
//Print "<tr>";
//Print "<th>Password:</th> <td>".$info['password'] . " </td></tr>"; 
} 
Print "</table>"; 
?>
Member Avatar for Dukane

I don't know if this will solve your whole problem but one thing is staring me in the face:

$data = mysql_query("SELECT title, first_name, surname, addr_line_1, addr_line_2, city, postcode, tel_number, mob_number, email FROM members where id = '$_post[id]'")or die(mysql_error());
$result = mysql_query($data)or die ("Query failed: " . mysql_error());

There should be no mysql_query() on the first line. You can also delete the or die at the end of that line. Instead, try this:

$data = "SELECT title, first_name, surname, addr_line_1, addr_line_2, city, postcode, tel_number, mob_number, email FROM members WHERE id = '$_post[id]'";
$result = mysql_query($data)or die ("Query failed: " . mysql_error());

Thanks Dukane i tried what u said & i got over that part of the problem but now it is giving me the abv error and wont display the information that i am asking for. The revised code below.

<?php 
ini_set('display_errors',1); 
error_reporting(E_ALL);
// Connects to your Database 
$dbhost = "localhost";  // variable holding host information
$dbname = "sportscentre";  // variable holding the name of the database
$dbuser = "*****";  // variable holding the username of the person using database account
$dbpass = "*****";  // variable holding password of the person using database account

$connection = mysql_connect($dbhost, $dbuser, $dbpass)or die("Cannot connect");

$connection = mysql_select_db($dbname)or die("cannot select DB");

$id = $_POST['id']; 

$data = "SELECT title, first_name, surname, addr_line_1, addr_line_2, city, postcode, tel_number, mob_number, email FROM members where id = '$id'";

$result = mysql_query($data)or die ("Query failed: " . mysql_error());
 
Print "<table border cellpadding=3>"; 
while($info = mysql_fetch_array( $data )) 
{ 
Print "<tr>"; 
Print "<th>Title:</th><td>".$info['title'] . "</td></tr>";
Print "<tr>";
Print "<th>First Name:</th> <td>".$info['first_name'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Surname:</th> <td>".$info['surname'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Address Line 1:</th> <td>".$info['addr_line_1'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Address Line 2:</th> <td>".$info['addr_line_1'] . " </td></tr>"; 
Print "<tr>";
Print "<th>City:</th> <td>".$info['city'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Postcode:</th> <td>".$info['postcode'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Tel Number:</th> <td>".$info['tel_number'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Mob Number:</th> <td>".$info['mob_number'] . " </td></tr>"; 
Print "<tr>";
Print "<th>Email:</th> <td>".$info['email'] . " </td></tr>"; 
//Print "<tr>";
//Print "<th>Username:</th> <td>".$info['username'] . " </td></tr>"; 
//Print "<tr>";
//Print "<th>Password:</th> <td>".$info['password'] . " </td></tr>"; 
} 
Print "</table>"; 
?>

it says it has a problem with this line,
while($info = mysql_fetch_array( $data ))

Member Avatar for Dukane

This is because the variable $data contains a string which is your SQL string. The actual data is in $result. So your line should be

while($info = mysql_fetch_array( $data ))

@Dukane
You made the same error as Newbi..the correct code is below (Don't worry about it, I've made worse mistakes :D):

while($info = mysql_fetch_array($result))

The reason for this is as Dukane explained...When you perform a query the query string is executed with the mysql_query() function. This function returns a special MySQL Result that you can then pass to mysql_fetch_array() or any other MySQL Result functions.

commented: OOOPS! I meant to type out what you typed out, but thank you for pointing out my mistake! Good catch! +3

Thank you that solved the problem

You're welcome! If your original problem is now solved, I ask that you mark this thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.