I am very new to working with PHP and could really use some help here. I am trying to write some php scripts that will display a text input box which will be used to search the database I have it connected to.

Right now, my problem is that the code I have keeps sending me to a page that says 'Object not found!' at the top with a 'Error 404' displayed towards the bottom. The code I am using for the page is the following:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTDxhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>Campbell Sales</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
</head>

<body>

<h1>Campbell Sales</h1>

<form name="form" action="search.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />
</form>

<?php

   // Connect and select a database
   // mysql_connect("localhost", "root", "");
   // mysql_select_db("cambellsales");
   $con = mysql_connect("", "root", "", "cambellsales");
   if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("cambellsales", $con);

   //Run a query
   $result = mysql_query("SELECT * FROM inventory") or die("Query failed with error: ".mysql_error());









echo "<table border='1' cellpadding='8' cellspacing='3'
	    summary=\"Table holds Cambell inventory information\">
	<tr>
	     <th>isle</th>
	     <th>col</th>
	     <th>r</th>
	     <th>rows</th>
	     <th>quantity</th>
	     <th>partnumber</th>
	     <th>surplus</th>
	     <th>description</th>
	     <th>cost</th>
	     <th>entryorder</th>
	     <th>icrr</th>
	     <th>irrc</th>
	     <th>rowm</th>
	</tr>";





// Loop through all table rows
while($row = mysql_fetch_array($result)) {
	echo "<tr>";
	echo "<td>" . $row['Isle'] . "</td>";
	echo "<td>" . $row['Col'] . "</td>";
	echo "<td>" . $row['R'] . "</td>";
	echo "<td>" . $row['Row'] . "</td>";
	echo "<td>" . $row['Quantity'] . "</td>";
	echo "<td>" . $row['PartNumber'] . "</td>";
	echo "<td>" . $row['Surplus'] . "</td>";
	echo "<td>" . $row['Description'] . "</td>";
	echo "<td>" . $row['Cost'] . "</td>";
	echo "<td>" . $row['EntryOrder'] . "</td>";
	echo "<td>" . $row['ICRR'] . "</td>";
	echo "<td>" . $row['IRRC'] . "</td>";
	echo "<td>" . $row['RowM'] . "</td>";
	echo "</tr>";
    }

    // Free result memory and close database connection
    mysql_free_result($result);
    mysql_close($con);


 ?>
 </table>
  </body>

  </html>

    Error 404 literally means that the server cannot find the file. Are you sure you've uploaded the "search.php" page to the server?

      Well, I am sure I didnt upload it because I havent created it. I didnt see that in the code. Like I said, I am very new to php. To be honest I got the code from a website that was giving tutorials on how to connect and search a database that I have created.

      I am not even sure what is supposed to be in that "search.php" page. Any help you can offer me in figuring this out would be greatly appreciated.

        I think you'll find search.php was what you were supposed to name the file. It's no big problem either rename your script, or easier still just change search.php to the name of your script.

          I would highly recommend that you separate your user input pages from your input processing pages. I usually just add a "_p" suffix to the page name (i.e. - the processing page for edit_user.php would be edit_user_p.php). There are several benefits to this development style:

          1) Bandwidth and processing is saved when users don't follow through on an action
          2) Re-posting of user input is rarely a concern and page navigation is simpler
          3) It breaks up code into smaller chunks that are easy to work with
          4) It makes pages easier to "template" and reuse

          I would assume that there are two pages in your example code:
          1) the user input page that you listed
          2) the search page, which probably combines processing and results (which is appropriate for a search function)

          The search page will take the input from the page you listed, perform the search based on the input, and display the results of the search.

          Note: You'll find that many developers will combine the input, search, and results into the same page, which I tend to discourage. It makes code more complicated than it needs to be, wastes bandwidth (if the user doesn't actually go through with the search, why load and process all of that code???), and it makes troubleshooting more difficult.

            Write a Reply...