Hi everyone,

I'm new to php and I'm working on a project, it's very typical that when you type in a search box and press the submit button, it will link you to a table with minimal content, but upon clicking a list on the table, it will link you again to the full detail information of your database,

here is my form code

]<html>
<form action="fetchDBAssets.php" method="POST">
search:<input type="text" name="assetSearch" />
<input type="submit" />
</form>
</html>

and here is my first form to show the brief table

<?php session_start();
error_reporting (E_ALL ^ E_NOTICE);



$con=mysql_connect("localhost","root","");
    if(!$con)
        {
            die('connection error' . mysql_error());
        }
    mysql_select_db("pcassets_db",$con);

$result=mysql_query("SELECT * FROM data WHERE (userFirstName='$_POST[assetSearch]' || pcName='$_POST[assetSearch]')");



    echo "<table border='1' name='table1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";


    while ( $row = mysql_fetch_array($result) )
       {
        echo "<tr>";
        echo "<td>" . "<a href='fetchDBAssetsWhole.php'>" . $row['userFirstName'] . "</td>" . "<td>" . $row['userLastName'] . "</td>";
         echo "<br/>";
       }
echo "</table>";
mysql_close($con);

What I want is when i click to firstname, it will link again to the full detail of my database which is firstname, lastname, department, position and so on. Can somebody help me with this? Hope to read your reply soon.

Thank you

Hi
if you are having id in your table

<a href='fetchDBAssetsWhole.php'>

Replace the above URL as below

<a href='fetchDBAssetsWhole.php?id=id='".$row['id']."''>

Hi,

thanks for the reply, and how is the code will be on the fetchDBAssetsWhole.php then?

using GET

$id = $_GET;

select * from tablename where id='$id'

Like this

Hi,

here is what I did on fetchDBAssetsWhole.php

<?php 

//error_reporting (E_ALL ^ E_NOTICE);




$con=mysql_connect("localhost","root","");
	if(!$con)
		{
			die('connection error' . mysql_error());
		}
	mysql_select_db("pcassets_db",$con);
	
	$ID=$_GET['id'];

	$result=mysql_query("SELECT * FROM data WHERE (pcID='$ID')");

	echo $row['userFirstName'] . " " . $row['userLastName'] . " " . $row['department'] . " " . $row['position'] ;
	
	
	/*while ( $row = mysql_fetch_array($result) )
	   {
		
		echo $row['userFirstName'] . " " . $row['userLastName'] ;
		 echo "<br/>";
	   }*/

mysql_close($con);


?>

Here is the error

Notice: Undefined variable: row in C:\wamp\www\DBASSETS\fetchDBAssetsWhole.php on line 19

I'm doing it wrong, please help me more and thank you for your support

Hi,

here is what I did on fetchDBAssetsWhole.php

<?php 

//error_reporting (E_ALL ^ E_NOTICE);




$con=mysql_connect("localhost","root","");
	if(!$con)
		{
			die('connection error' . mysql_error());
		}
	mysql_select_db("pcassets_db",$con);
	
	$ID=$_GET['id'];

	$result=mysql_query("SELECT * FROM data WHERE (pcID='$ID')");

	echo $row['userFirstName'] . " " . $row['userLastName'] . " " . $row['department'] . " " . $row['position'] ;
	
	
	/*while ( $row = mysql_fetch_array($result) )
	   {
		
		echo $row['userFirstName'] . " " . $row['userLastName'] ;
		 echo "<br/>";
	   }*/

mysql_close($con);


?>

Here is the error

Notice: Undefined variable: row in C:\wamp\www\DBASSETS\fetchDBAssetsWhole.php on line 19

I'm doing it wrong, please help me more and thank you for your support

Hi Please Use the below code to test.

<?php session_start();
error_reporting (E_ALL ^ E_NOTICE);

$con=mysql_connect("localhost","root","");
if(!$con)
{
die('connection error' . mysql_error());
}
mysql_select_db("pcassets_db",$con);

$result=mysql_query("SELECT * FROM data WHERE (userFirstName='$_POST[assetSearch]' || pcName='$_POST[assetSearch]')");



echo "<table border='1' name='table1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";


while ( $row = mysql_fetch_array($result) )
{
echo "<tr>";
echo "<td>" . "<a href='fetchDBAssetsWhole.php?id='".$row['pcID']."''>" . $row['userFirstName'] . "</td>" . "<td>" . $row['userLastName'] . "</td>";
echo "<br/>";
}
echo "</table>";
mysql_close($con);

fetchDBAssetsWhole.php

<?php 

//error_reporting (E_ALL ^ E_NOTICE);




$con=mysql_connect("localhost","root","");
	if(!$con)
		{
			die('connection error' . mysql_error());
		}
	mysql_select_db("pcassets_db",$con);
	
	$ID=$_GET['id'];

	$result=mysql_query("SELECT * FROM data WHERE pcID='$ID'");
	$row = mysql_fetch_array($result);

	echo $row['userFirstName'] . " " . $row['userLastName'] . " " . $row['department'] . " " . $row['position'] ;
	
	
	/*while ( $row = mysql_fetch_array($result) )
	   {
		
		echo $row['userFirstName'] . " " . $row['userLastName'] ;
		 echo "<br/>";
	   }*/

mysql_close($con);


?>

Hi,

I tried the code, and here is the error now

Notice: Undefined variable: _result in C:\wamp\www\DBASSETS\fetchDBAssetsWhole.php on line 18

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\DBASSETS\fetchDBAssetsWhole.php on line 18

Hi sorry for the script.

I need some information, you are getting the first name by POST method and check the field(pcName) name in table

po1.php

<html>
<form action="oo.php" method="POST">
search:<input type="text" name="assetSearch" />
<input type="submit" />
</form>
</html>

oo.php

<?php session_start();
error_reporting (E_ALL ^ E_NOTICE);

$con=mysql_connect("localhost","root","123");
if(!$con)
{
die('connection error' . mysql_error());
}
mysql_select_db("test",$con);
?>
<table border='1' name='table1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<?php
$result="SELECT * FROM data WHERE (userFirstName='$_POST[assetSearch]' || pcName='$_POST[assetSearch]')";
$q = mysql_query($result,$con);
while( $row = mysql_fetch_array($q))
{
?>
<tr>
<td><a href="fetchDBAssetsWhole.php?id=<?php echo $row['pcID'];?>"><?php echo $row['userFirstName']; ?></a></td>
<td><?php echo $row['userLastName']; ?></td>
</tr>
<?php } mysql_close($con); ?>
</table>

fetchDBAssetsWhole

<?php 

//error_reporting (E_ALL ^ E_NOTICE);




$con=mysql_connect("localhost","root","123");
	if(!$con)
		{
			die('connection error' . mysql_error());
		}
	mysql_select_db("test",$con);
	
	$ID=$_GET['id'];

	$result=mysql_query("SELECT * FROM data WHERE pcID='$ID'");
	$row = mysql_fetch_array($result);

	echo $row['userFirstName'] . " " . $row['userLastName'] . " " . $row['dob'] . " " . $row['birthplace'] ;
	
	
	/*while ( $row = mysql_fetch_array($result) )
	   {
		
		echo $row['userFirstName'] . " " . $row['userLastName'] ;
		 echo "<br/>";
	   }*/

mysql_close($con);


?>

Note: check pcName field is the table

Thanks Man, all is working now, you're a genius, many thanks!!!

Thanks Man, all is working now, you're a genius, many thanks!!!

Hi Don't use you're a genius for me Man