I have a simple search feature that searches 3 fields in 3 separate tables
in a MySQL db, and I'm getting an 'undefined index' error, but only in the
first section (first table)of the results. The undefined index is tied to
the docs.projID in the "if ($row_search['docs.projID'] == 1)". This if
statement is there to control to format of the link as pages are in
different depths of subfolders depending on security needs. Googling this
sort of error seems to reflect problems with the $_POST['keyword'] not
existing when the results are first listed, so I moved the PHP results code
from it's own page (search.php) to the main page, which didn't help. I have
tried several different things and can't seem to get it working right. Here
is what I have:
Form:
<form id="search" name="search" method="post" action="<?php echo
$currentPage?>" >
SEARCH<br />
<input name="keyword" type="text" size="20" value=""/>
<input type="image" name="Submit"
src="images/team_icon_go_bt n.gif" />
</form>
Results:
<?php if (isset($_POST['search']))
{
$keyword = $_POST['keyword'];
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct docURL, docTitle, docDesc, docs.projID,
groupCode, projCode, catName FROM docs
JOIN subcat on subcat.subcatID =docs.subcatID
JOIN cat on cat.catID = subcat.catID
JOIN groups on groups.groupID= proj.groupID
JOIN proj on proj.projID=doc s.projID
WHERE proj.projID=doc s.projID AND docURL LIKE '%$keyword%' OR docTitle LIKE
'%$keyword%' OR docDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
$proj = $row_search['projCode'];
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No internal documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Inter nal Documents:</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php
do { ?>
<tr>
<td>
<a href="<?php if ($row_search['docs.projID'] == 1) {
echo $row_search['catName']."/".$row_sear ch['docURL'];
}
else {
echo
$row_search['groupCode']."/".$row_sear ch['projCode']."/".$row_sear ch['catName']."/".$row_sear ch['docURL'];
?>"><?php echo $row_search['docTitle'];
} ?></a></td>
<td><?php echo $row_search['docDesc']; ?></td><td><?php echo
$row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct toolURL, toolName, toolDesc, tools.projID,
projCode FROM tools
JOIN proj on proj.projID=too ls.projID WHERE toolURL LIKE '%$keyword%' OR
toolName LIKE '%$keyword%' OR toolDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No tools matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Tools :</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['toolURL']; ?>"><?php echo
$row_search['toolName']; ?></a></td><td><?php echo $row_search['toolDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct pageURL, pageName, pageDesc, links.projID,
projCode FROM links
JOIN proj on proj.projID=lin ks.projID WHERE pageURL LIKE '%$keyword%' OR
pageName LIKE '%$keyword%' OR pageDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No external documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Exter nal Documents:</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['pageURL']; ?>"><?php echo
$row_search['pageName']; ?></a></td><td><?php echo $row_search['pageDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_free_resu lt($search);
}
?>
All guidance is welcome. Maybe I should move the if statement out of the
link or assign a variable. I'm considering changing all of my links in the
db to absolute URLs instead of relative, as this mapping to the location of
a page has become a programming overload nightmare. Perhaps this would
resolve my issue.
Thanks,
Christina
in a MySQL db, and I'm getting an 'undefined index' error, but only in the
first section (first table)of the results. The undefined index is tied to
the docs.projID in the "if ($row_search['docs.projID'] == 1)". This if
statement is there to control to format of the link as pages are in
different depths of subfolders depending on security needs. Googling this
sort of error seems to reflect problems with the $_POST['keyword'] not
existing when the results are first listed, so I moved the PHP results code
from it's own page (search.php) to the main page, which didn't help. I have
tried several different things and can't seem to get it working right. Here
is what I have:
Form:
<form id="search" name="search" method="post" action="<?php echo
$currentPage?>" >
SEARCH<br />
<input name="keyword" type="text" size="20" value=""/>
<input type="image" name="Submit"
src="images/team_icon_go_bt n.gif" />
</form>
Results:
<?php if (isset($_POST['search']))
{
$keyword = $_POST['keyword'];
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct docURL, docTitle, docDesc, docs.projID,
groupCode, projCode, catName FROM docs
JOIN subcat on subcat.subcatID =docs.subcatID
JOIN cat on cat.catID = subcat.catID
JOIN groups on groups.groupID= proj.groupID
JOIN proj on proj.projID=doc s.projID
WHERE proj.projID=doc s.projID AND docURL LIKE '%$keyword%' OR docTitle LIKE
'%$keyword%' OR docDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
$proj = $row_search['projCode'];
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No internal documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Inter nal Documents:</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php
do { ?>
<tr>
<td>
<a href="<?php if ($row_search['docs.projID'] == 1) {
echo $row_search['catName']."/".$row_sear ch['docURL'];
}
else {
echo
$row_search['groupCode']."/".$row_sear ch['projCode']."/".$row_sear ch['catName']."/".$row_sear ch['docURL'];
?>"><?php echo $row_search['docTitle'];
} ?></a></td>
<td><?php echo $row_search['docDesc']; ?></td><td><?php echo
$row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct toolURL, toolName, toolDesc, tools.projID,
projCode FROM tools
JOIN proj on proj.projID=too ls.projID WHERE toolURL LIKE '%$keyword%' OR
toolName LIKE '%$keyword%' OR toolDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No tools matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Tools :</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['toolURL']; ?>"><?php echo
$row_search['toolName']; ?></a></td><td><?php echo $row_search['toolDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_select_db ($database_webs ite, $website);
$query_search = "SELECT Distinct pageURL, pageName, pageDesc, links.projID,
projCode FROM links
JOIN proj on proj.projID=lin ks.projID WHERE pageURL LIKE '%$keyword%' OR
pageName LIKE '%$keyword%' OR pageDesc LIKE '%$keyword%'";
$search = mysql_query($qu ery_search, $website) or die(mysql_error ());
$row_search = mysql_fetch_ass oc($search);
$totalRows_sear ch = mysql_num_rows( $search);
?>
<?php if ($totalRows_sea rch < 1)
{
echo "No external documents matched your request.";
}
else {?>
<p><table width=95%>
<tr><td colspan="3"><fo nt size="+1">Exter nal Documents:</font></td>
</tr>
<tr>
<td><strongLi nk </strong></td>
<td<strong>Desc ription</strong></td>
<td<strong>Proj ect </strong></td>
</tr>
<?php do { ?>
<tr>
<td>
<a href="<?php echo $row_search['pageURL']; ?>"><?php echo
$row_search['pageName']; ?></a></td><td><?php echo $row_search['pageDesc'];
?></td><td><?php echo $row_search['projCode']; ?></td>
</tr>
<?php } while ($row_search = mysql_fetch_ass oc($search)); ?>
</table>
<?php }?>
</p>
<?php
mysql_free_resu lt($search);
}
?>
All guidance is welcome. Maybe I should move the if statement out of the
link or assign a variable. I'm considering changing all of my links in the
db to absolute URLs instead of relative, as this mapping to the location of
a page has become a programming overload nightmare. Perhaps this would
resolve my issue.
Thanks,
Christina
Comment