1 Attachment(s)
PHP & MySQL Data Retrieval Problem
Alright programmers out there, I am currently working on a database for my company which has a web interface. The user is given a series of text boxes and drop downs to input project information, as well as a browse for file button to input a link to a pdf. the input works fine.
Now however, I am working on a retrieval system for the data. I give the user a more stripped down list of text boxes, and await their input.
http://www.greenfishpress.com/golder/goldersearch.php
When the user submits the form I run search.php [attached], which is supposed to take the text boxes, check to see if they are blank - if so they change its value to wildcard. Then I run an SQL select statement to grab whatever the user has looked for [complete wild card if no data is input] and output it into a table showing select information from the table.
search.php:
Code:
<?php
echo("******><head><title>Search Results</title></head><body>");
//variables for server to connect to, username and password to use
//this information is put into variable so that if server changes
//you can edit all values from here
$address="localhost";
$username="XXX";
$password="XXX";
$db_name="zandrew_golder";
//compose in_bday from selected date values
$in_bday= $in_year . "-" . $in_month . "-" . $in_day;
//switch all the input to uppercase for the search
$in_morg_num = strtoupper($in_morg_num);
$in_num = strtoupper($in_num);
$in_short_title = strtoupper($in_short_title);
$in_prop_num = strtoupper($in_prop_num);
$in_mgr = strtoupper($in_mgr);
//connect to the database, store response in $dbcnx
$dbcnx=@mysql_connect($address, $username, $password);
if(!$dbcnx){
echo("<p>Unable to connect to the database at this time</p>");
exit();
}
if(!@mysql_select_db($db_name, $dbcnx)) {
echo("<p>Unable to locate the database at this time");
exit();
}
if($submit== "search"){
//if anything submitted was null, change it to wildcard
if($in_num==""){$in_num="*";}
if($in_morg_num==""){$in_morg_num="*";}
if($in_prop_num==""){$in_prop_num="*";}
if($in_mgr==""){$in_morg_num="*";}
if($in_budget1==""){$in_budget1="*";}
if($in_budget2==""){$in_budget2="*";}
if($in_short_title==""){$in_short_title="*";}
if($in_bday==""){$in_bday="*";}
if($in_dept==""){$in_dept="*";}
if($in_office==""){$in_office="*";}
if($in_prov==""){$in_prov="*";}
if($in_year==""){$in_year="*";}
if($in_month==""){$in_month="*";}
if($in_day==""){$in_day="*";}
if($in_budget==""){$in_budget="*";}
//while($count != 15){
// if(($inlist[$count]==""){$inlist[$count]="*";}
//}
$sql="SELECT proj_pdf, proj_num, proj_short_title, proj_morg_num, proj_mgr FROM tblprojects WHERE proj_mgr='$in_mgr' AND proj_num='$in_num' AND proj_morg_num='$in_morg_num' AND proj_prop_num='$in_prop_num' AND proj_budget ='$in_budget' AND proj_short_title='$in_short_title' AND proj_bday='$in_bday' AND proj_dept='$in_dept' AND proj_office_name='$in_office' AND proj_prov_name='$in_prov' AND proj_year='$in_year' AND proj_day='$in_day' AND proj_month='$in_month'";
//put the return value into the var $result
$result=mysql_query($sql);
if(!$result){
echo("<p>search could not complete" . mysql_error() . "</p>");
exit();
}
echo("<table border='1'><tr><th>PDF</th><th>Project Number</th><th>Project Short Title</th><th>Morguard Number</th><th>Manager</th></tr>");
while($row=mysql_fetch_assoc($result)){
echo("<tr><td>" . $row[proj_pdf] . "</td>");
echo("<td>" . $row[proj_num] . "</td>");
echo("<td>" . $row[proj_short_title] . "</td>");
echo("<td>" . $row[proj_morg_num] . "</td>");
echo("<td>" . $row[proj_mgr] . "</td></tr>");
}
echo("</table>");
}
echo("<br /><br /><a href='golderhome.html'><p>home</p>");
echo("</body>*******>");
?>