hello:

I'm working on this code that receives a variable via url and performs a mysql search for records using the value of the variable as the key word. I'm using the following code --which I'm currently using successfully on another section of my project, but experiencing problems in a different section.

The code is the same with a few minor changes (database and table connection etc), for some odd reason, the page comes out blank without any errors. I tried changing the connection information with intentional false access info to see if an error would be produced, still nothing. I'm a bit puzzled. Here is the code:

<html>

<head>
<meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Content of Search Results</title> <!--<link rel="stylesheet" type="text/css" href="../music/.keycode2.css"> --></head> <body topmargin="0">

<hr color="#C0C0C0" size="1">
<table border="0" width="100%" id="resultbar" bgcolor="#E2EBED">
	<tr>
<td>Customer's Job Cost History</td>
	</tr>
</table>
<div class="graph" style="margin-left: 0px; margin-right: 0px;" display="inline">
    <align="left">
		<hr size="1" color="#CCCCCC">

<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
  // Get the search variable from URL
  $var = @$_GET["clientID"] ;
  $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 "<p>Please enter a search...</p>";
  exit;
  }

// check for a search parameter
if (!isset($var))
  {
  echo "<p>We dont seem to have a search parameter!</p>";
  exit;
  }
//connect to your database
mysql_connect("xxxxxxxxx", "xxxxxxxxx","xxxxxxxxxxxx"); //(host, username, password)

//specify database
mysql_select_db("shop") or die("Unable to select database"); //select which database we're using


// Build SQL Query
//$query = "select * from billofservice where clientID like '%$trimmed%' order by vehicleid "; // EDIT HERE and specify your table and field names for the SQL query 
//echo "<br /><br />" . $query . "<br /><br />"; //die(); //$query = "select  hashed_name = \"%$trimmed%\" from music"; //echo "<br /><br />" . $query . "<br /><br />";
$query = "select * from billofservice where vehicleid  like '%$trimmed%' order by vehicleid ";

 $results=mysql_query($query);
 $numrows=mysql_num_rows($results);
  
if ($numrows == 0)
  {
  //echo "<h4>Results</h4>";
  echo "<p>Sorry, your search for <a href=\"http://xxxxxxxxxxxxxxxxxxxxx/newsounds.php\?q=$var\">&quot;" . $trimmed . "&quot;</a> in the music category returned zero results</p>";
  echo "This may simply be that our records has not been updated with detailed information of this search. Please click on the link above, 
  this will prompt our system to initiate the process for detailed information concerning &quot;" . $trimmed . "&quot sound. <p>It may also be possible that you have selected the wrong category for your search. A review of your search category selection may resolve the issue.</p><p> Thank you!</p>";

  echo "--------------------------------------------------------------------------------------------------------";

// google
 //echo "<p><a href=\"http://www.google.com/search?q=" . $trimmed . "\"target=\"_blank\" title=\"Look up " . $trimmed . " on Google\">Click here!</a> to try the  //search on google</p>";
  }

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

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

// display what the person searched for
//echo "-----------------------------------------------------------------------------------------------------";
echo "<p>Additional Details information the search on: &quot;" . $var . "&quot;</p>";
echo "-----------------------------------------------------------------------------------------------------";

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

// now you can display the results returned
  
  while ($row= mysql_fetch_array($result)) {
  $title1 = $row["invoicenum"];
  $title2 = $row["servicedesc"];
  $title3 = $row["vehicleid"];
  $title4 = $row["servicearea"];
  $title5 = $row["total"];
  $title6 = $row["paid"];
  $title7 = $row["Balancedue"];
  $title8 = $row["date "];
  
  
  echo "<p><strong>Invoice Number:</strong>&nbsp;$title1</P>" ;
  $count++ ;
  echo "<p><strong>Service Description:</strong>&nbsp;$title2 </p>";
  $count++ ;
  echo "<p><strong>Client ID:</strong>&nbsp;$title3 </p>";
  $count++ ;
  echo "<p><strong>Service Area:</strong>&nbsp;$title4</p>" ;
  $count++ ;
  echo "<p><strong>Job Total Cost:</strong>&nbsp;$title5</p>" ;
  $count++ ;
  echo "<p><strong>Payment:</strong>&nbsp;$title6</P>" ;
  $count++ ;
  echo "<p><strong>Balance Due:</strong>&nbsp;$title7</P>" ;
  $count++ ;
  echo "<p><strong>Date of The Invoice</strong>&nbsp;$title8</P>" ;
  $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>";
  ?>
	
		</body></p></td>
		</tr>
	</div>	

&nbsp;</html>

for the referring url variable I have something like this:

onclick=\"window.location= 'invoicehistory.php?var=$clientID'

Can someone take a look at it to see if they catch something I'm not seeing.

Thanks,
Mossa

Recommended Answers

All 10 Replies

What is showing in the code on the loaded page? (View > Page Source)

thanks for the reply. only this is showing:

<html>

<head>
<meta http-equiv="Content-Language" content="en-us"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Content of Search Results</title> <!--<link rel="stylesheet" type="text/css" href="../music/.keycode2.css"> --></head> <body topmargin="0">

<hr color="#C0C0C0" size="1">
<table border="0" width="100%" id="resultbar" bgcolor="#E2EBED">
	<tr>
<td>Customer's Job Cost History</td>
	</tr>
</table>
<div class="graph" style="margin-left: 0px; margin-right: 0px;" display="inline">
    <align="left">
		<hr size="1" color="#CCCCCC">

and if I were to remove that section, absolutely nothing is shown.

You have 2 errors in your code before the bit that doesn't process. I doubt it will fix the problem but you probably want to fix them.

Line 12:

<div class="graph" style="margin-left: 0px; margin-right: 0px;" display="inline">

Should be:

<div class="graph" style="margin-left: 0px; margin-right: 0px; display: inline;">

Line 13:

<align="left">

This isn't needed as the default alignment is the left and there is no <align> tag.

Thanks for pointing this out. I'll modify. Though I had even removed this section during debugging and still the page remained blank.

Which is the reason I doubted it would fix it.

Here's an obvious question I should have already asked:

Does the server you're using support PHP?

Nevermind that, I found your error.

Remove every instance you have of exit; .

From what I can see, that's on lines 29 and 36.

When exit; is called, it stops rendering all code after it which is why nothing is displayed.

Borzoi, you are correct! Those two instances of exit; were causing the failure.
Thank you very much

You're welcome.

It was quite odd, because the "exit;" served the purpose of stopping the script from moving forward if the string from the url was empty, it therefor would display a message and exit the script. None was working! Commenting out both exits; did it. I went back readjusted those strings and all is well.

Best,
Mossa

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.