0

I'm new to php mysql. i'm creating website for my community. help me out...

My web page has one search page. user to feed few letters in the search box. it is proceesed and the result displaced in a table.

here is my code
for getting input : search.php

<html>
<body>
<form name="form" action="searchproc.php" method="get">
  <input type="text" class="textfield" name="name" />
  <input type="submit" name="Submit" value="Search" />
</form>
</body>
</html>

for processing the searched query : searchproc.php

<html>
<body>
<?php
// Inialize session
session_start();

// Check, if user is already login, then jump to secured page
if (!isset($_SESSION['empno'])) {
        header('Location: login.php');
}
?>
<?php
include 'config.php';
include 'opendb.php';
  // Get the search variable from URL

  $var = @$_GET['name'] ;
  $trimmed = trim($var);
 //trim whitespace from the stored variable

// rows to return
$limit=10; 

// check for an empty string and display a message.
if ($trimmed == "")
  {
  echo "Please enter a search...";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "We dont seem to have a search parameter!";
  exit;
  }

// Build SQL Query  
$query = "select * from detail where name like \"%$trimmed%\"  
  order by empno"; // EDIT HERE and specify your table and field names for the SQL query

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  {
  echo "Results</br></br>";
  echo "Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results";
  exit();
  }

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "You searched for: &quot;" . $var . "&quot;";

// begin to show results set
$count = 1 + $s ;

// now you can display the results returned
echo "<table border='1'>
<tr>
<th>Serial No</th>
<th>Emp No</th>
<th>Name</th>
<th>Branch</th>
</tr>";

  while ($row= mysql_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $count. "</td>";
echo "<td>" . $row['empno'] . "</td>";
echo '<td> <a href="profile.php?uid='.$row['empno'].'">'.$row['name'].'</a> </td>';
echo "<td>" . $row['branch'] . "</td>";
echo "</tr>";


  $count++ ;
  }

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link
  $news=$s+$limit;

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
  }

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";
  echo "<br />";
    
include 'closedb.php';
?>
</body>
</html>

Now, the result is displayed in the table perfectly, with a hyperlink at each name. However, when i click the link profile of the employee is not genereated. shows lot of errors. please help.

code for profile.php

<html>
<body>
<?php
// Inialize session
session_start();

// Check, if user is already login, then jump to secured page
if (!isset($_SESSION['empno'])) {
        header('Location: login.php');
}
?>
<?php
include 'config.php';
include 'opendb.php';
$id = $_GET['empno'];
$query = "SELECT * FROM detail WHERE empno = '$id' LIMIT 1";
$result = mysql_query($query) or die("Error processing query. ".mysql_error());
$empno = mysql_fetch_array($result);
echo "<table width = '400' border = '1'>";
echo "<tr>";
echo "<td colspan = '2'>".$empno->empno."</td>";
echo "</tr>";
echo "<tr>";
echo "<td>".$empno->name."</td>";
echo "<td>".$empno->branch."</td>";
echo "</tr>";
echo "</table>";

include 'closedb.php'
?>
</body>
</html>
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by afatn
0

What does the error show ? However, you will not get any value with $_GET. You was using 'uid' in the url. I'm not sure, without seeing your error status. Perhaps, it may solve your problem. Replace line 15 in profile.php with the line below.

$id = $_GET['uid'];

Hope this help.

0

Thanks zero13,
replacing line 15 of profile.php & replacing line 18 $empno = mysql_fetch_array($result); with $empno = mysql_fetch_object($result); solved my worries.

Edited by afatn: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.