My senior project needs your help:search on my site.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
annanicole
Forum Newbie
Posts: 2
Joined: Sun Aug 29, 2004 10:04 am

My senior project needs your help:search on my site.

Post by annanicole »

Ok I am a newbie so here goes.
I have created a database with table. I created my webpages using recordsets in Dreamweaver. I am now trying to integrate a search into my site.

Here is my search code on my index page:

Code: Select all

<td width="99%" rowspan="2" align="center"><form action="results.php" method="post" name="area" id="area">
                                  <input name="area" type="text" id="area">
                                  <input type="submit" name="Submit" value="Submit">
                                </form> </td>


On my results page here is the code:

Code: Select all

<?php require_once('Connections/Aiph.php'); ?>
<?php
{ 
   echo("<font face="tahoma" size="3" color="green"><b>Results for $words</b></font><br><br>"); 
   $location = "*******"; // database host (localhost)
   $username = "*****"; // mysql username
   $password = "*****"; //mysql password
   $database = "*****"; //mysql database name

   
   $conn = mysql_connect("$location","$username","$password"); 
   if (!$conn) die ("Could not connect MySQL"); 
   mysql_select_db($database,$conn) or die ("Could not open database"); 
   
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$sql = mysql_query("SELECT CityArea,  FROM 'restaurant' WHERE CityArea LIKE %$area% ") or die (mysql_error());
?>
}

$maxRows_Recordset5 = 5;
$pageNum_Recordset5 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset5'])) {
  $pageNum_Recordset5 = $HTTP_GET_VARS['pageNum_Recordset5'];
}
$startRow_Recordset5 = $pageNum_Recordset5 * $maxRows_Recordset5;

mysql_select_db($database_Aiph, $Aiph);
$query_Recordset5 = "$sql";
$query_limit_Recordset5 = sprintf("%s LIMIT %d, %d", $query_Recordset5, $startRow_Recordset5, $maxRows_Recordset5);
$Recordset5 = mysql_query($query_limit_Recordset5, $Aiph) or die(mysql_error());
$row_Recordset5 = mysql_fetch_assoc($Recordset5);

if (isset($HTTP_GET_VARS['totalRows_Recordset5'])) {
  $totalRows_Recordset5 = $HTTP_GET_VARS['totalRows_Recordset5'];
} else {
  $all_Recordset5 = mysql_query($query_Recordset5);
  $totalRows_Recordset5 = mysql_num_rows($all_Recordset5);
}
$totalPages_Recordset5 = ceil($totalRows_Recordset5/$maxRows_Recordset5)-1;

Ok the problem I am having is it does not work.

This is the live site:stu.aii.edu/~anl183/php/index.php

I want to preserve the look of my site so I am not sure what to do.

As I have said I am new at PHP and I am sure that there is a massive mistake I have made. I apologize in advance for my ignorance. I have tried to read tutorials, and the PHP guide but I am not grasping the situation.


Thanks for anyone's help.

Nicole


feyd | swapped

Code: Select all

into

Code: Select all

tag.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ignoring the syntax errors in your query.. and assuming this code isn't nearly complete, what's line 284 (and the few lines before and after too)?
annanicole
Forum Newbie
Posts: 2
Joined: Sun Aug 29, 2004 10:04 am

Post by annanicole »

there is no line 284. I looked and am unable to find one. here is the entire code.

Code: Select all

<?php require_once('Connections/Aiph.php'); ?>
<?php
{ 
   echo("<font face="tahoma" size="3" color="green"><b>Results for $words</b></font><br><br>"); 
   $location = "*****"; // database host (localhost)
   $username = "*****"; // mysql username
   $password = "*****"; //mysql password
   $database = "*****"; //mysql database name

   
   $conn = mysql_connect("$location","$username","$password"); 
   if (!$conn) die ("Could not connect MySQL"); 
   mysql_select_db($database,$conn) or die ("Could not open database"); 
   
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];

$sql = mysql_query("SELECT CityArea,  FROM 'restaurant' WHERE CityArea LIKE %$area% ") or die (mysql_error());
?>
}

$maxRows_Recordset5 = 5;
$pageNum_Recordset5 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset5'])) {
  $pageNum_Recordset5 = $HTTP_GET_VARS['pageNum_Recordset5'];
}
$startRow_Recordset5 = $pageNum_Recordset5 * $maxRows_Recordset5;

mysql_select_db($database_Aiph, $Aiph);
$query_Recordset5 = "$sql";
$query_limit_Recordset5 = sprintf("%s LIMIT %d, %d", $query_Recordset5, $startRow_Recordset5, $maxRows_Recordset5);
$Recordset5 = mysql_query($query_limit_Recordset5, $Aiph) or die(mysql_error());
$row_Recordset5 = mysql_fetch_assoc($Recordset5);

if (isset($HTTP_GET_VARS['totalRows_Recordset5'])) {
  $totalRows_Recordset5 = $HTTP_GET_VARS['totalRows_Recordset5'];
} else {
  $all_Recordset5 = mysql_query($query_Recordset5);
  $totalRows_Recordset5 = mysql_num_rows($all_Recordset5);
}
$totalPages_Recordset5 = ceil($totalRows_Recordset5/$maxRows_Recordset5)-1;

$queryString_Recordset5 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
  $params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset5") == false && 
        stristr($param, "totalRows_Recordset5") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset5 = "&" . implode("&", $newParams);
  }
}
$queryString_Recordset5 = sprintf("&totalRows_Recordset5=%d%s", $totalRows_Recordset5, $queryString_Recordset5);
?>
 
<html>



<head>

<meta http-equiv="Content-Language" content="en-us">

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>Cross Country Cuisine</title>

<link href="box.css" rel="stylesheet" type="text/css">
</head>



<body bgcolor="9E9F80" text="#663300" link="9E9F80" vlink="9E9F80" alink="9E9F80" leftmargin="0" topmargin="0">

<div align="center">

  <center>

    <table width="760" height="513" border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" bgcolor="#ffffff" id="AutoNumber1" style="border-collapse: collapse">

      <tr>

        <td width="760" height="511" valign="top"> 
          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2">

        <tr>

              <td width="73%" height="99"> 
                <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber6">

            <tr>

                    <td width="20%" align="center" valign="bottom"> <img border="0" src="http://stu.aii.edu/~anl183/images/logo.gif" width="60" height="60"></td>

                    <td width="80%" valign="bottom"> <font color="#663300" face="Arial Black"><font color="9E9F80" size="6">Cross 

                      Country Eats</font><br>
                      </font><b><font size="1" color="#8D9460" face="Verdana"> 
                      <font color="FC0D13" size="3">locating restaraunts nationwide.</font></font></b></td>

            </tr>

          </table>

          </td>

              <td width="27%" align="right"><div align="center"><font color="#FF0000" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Search 
                  Results </strong></font></div></td>

        </tr>

        <tr>

              <td width="52%" background="php/images/2.jpg">

          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5">

            <tr>

                    <td width="25%" align="right" background="http://stu.aii.edu/~anl183/images/2.jpg"><font size="2">&nbsp;&nbsp; 
                      </font><b><font face="Verdana" size="1" color="#FFFFFF">&nbsp;</font></b></td>

                    <td width="60%" height="19" align="left" background="http://stu.aii.edu/~anl183/images/2.jpg"> 
                      <div align="center"><b> <font face="Verdana" size="1" color="#FFFFFF"><a href="index.php"><font color="#F9FFFE">home</font></a> 
                        |<a href="mailto:anl183"><font color="#F9FFFE"> contact 
                        us</font></a> | <a href="php/index.html"><font color="#F9FFFE">about 
                        us</font></a></font></b></div></td>

            </tr>

          </table>

          </td>

              <td width="48%" height="19" align="right" background="http://stu.aii.edu/~anl183/images/2.jpg">&nbsp; 
              </td>

        </tr>

            <tr> 
              <td width="100%" height="350" colspan="2" valign="top"> 
                <table width="758" height="73" border="0" cellpadding="0" cellspacing="0" bordercolor="#111111" id="AutoNumber3" style="border-collapse: collapse">
                  <tr> 
                    <td height="73" valign="top"> 
                      <div align="center"> 
                        <center>
                        </center>
                      </div>
                      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="103%" id="AutoNumber7" background="php/images/9.jpg">
                        <tr> 
                          <td width="100%" height="25" bgcolor="#FFFFFF"> <table width="96%" border="0" cellpadding="0" cellspacing="0" id="AutoNumber9" style="border-collapse: collapse">
                              <tr> 
                                <td width="100%" height="1" valign="top"> <div align="left"> 
                                    <table width="757" border="0" align="center" cellpadding="0" cellspacing="0" id="AutoNumber11" style="border-collapse: collapse">
                                      <tr> 
                                        <td height=5></td>
                                      </tr>
                                      <tr> 
                                        <td><font size="1">&nbsp; </font> <table width="760" border="0" cellpadding="0" cellspacing="0" bordercolor="9E9F80" class="unnamed1">
                                            <tr> 
                                              <td height="193"> <?php do { ?>
                                                <table width="760" border="0" cellpadding="0" cellspacing="0" bordercolor="#999999" class="unnamed1">
                                                  <tr class="text"> 
                                                    <td colspan="2"><font color="#000000" size="5" face="Verdana, Arial, Helvetica, sans-serif"><strong><?php echo $row_Recordset5['City']; ?></strong></font></td>
                                                    <td><font color="#000000" size="4" face="Verdana, Arial, Helvetica, sans-serif">&nbsp;</font></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td colspan="3"><font color="#000000" size="4" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_Recordset5['Name']; ?></font><font face="Verdana, Arial, Helvetica, sans-serif"><strong></strong></font></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td colspan="3"><font size="3" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $row_Recordset5['Address']; ?></font></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td>&nbsp;</td>
                                                    <td><font size="2">&nbsp;</font></td>
                                                    <td><font size="2">&nbsp;</font></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td width="241"><font size="3"><?php echo $row_Recordset5['CityArea']; ?></font></td>
                                                    <td width="239"><?php echo $row_Recordset5['Cuisine']; ?></td>
                                                    <td width="280"><?php echo $row_Recordset5['Telephone']; ?></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td>&nbsp;</td>
                                                    <td colspan="2">&nbsp;</td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td colspan="3"></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td colspan="3"><strong><font size="3"><?php echo $row_Recordset5['Description']; ?></font></strong></td>
                                                  </tr>
                                                  <tr class="text"> 
                                                    <td colspan="3">&nbsp;</td>
                                                  </tr>
                                                </table>
                                                <?php } while ($row_Recordset5 = mysql_fetch_assoc($Recordset5)); ?>
<div align="center"> 
                                                  <table width="75%" border="0">
                                                    <tr> 
                                                      <td width="50%"><a href="<?php printf("%s?pageNum_Recordset5=%d%s", $currentPage, max(0, $pageNum_Recordset5 - 1), $queryString_Recordset5); ?>">Previous</a></td>
                                                      <td width="50%"><div align="right"><a href="<?php printf("%s?pageNum_Recordset5=%d%s", $currentPage, min($totalPages_Recordset5, $pageNum_Recordset5 + 1), $queryString_Recordset5); ?>">Next</a></div></td>
                                                    </tr>
                                                  </table>
                                                </div>
                                                
                                              </td>
                                            </tr>
                                          </table>
                                          <p align="justify"><font face="Verdana" size="1" color="#663300"> 
                                            </font></p>
                                          <p align="justify"><font face="Verdana" size="1" color="#663300"><br>
                                            &nbsp;</font></p></td>
                                      </tr>
                                    </table>
                                  </div></td>
                              </tr>
                            </table></td>
                        </tr>
                      </table></td>
                  </tr>
                </table>

          </td>

        </tr>

        <tr>

              <td width="100%" colspan="2" height="1" bgcolor="#616541" background="http://stu.aii.edu/~anl183/images/2.jpg" align="right"> 

                <div align="center"><font face="Verdana" size="1" color="#FFFFFF">© 

                  Copyright 2004.Anna Nicole Lee</font></div></td>

        </tr>

        <tr>

          <td width="100%" colspan="2">

          <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" width="100%" id="AutoNumber13">

                  <tr> 

                    <td width="8%" align="center">&nbsp;</td>

                    <td width="92%">&nbsp;</td>

                  </tr>

                </table>

          </td>

        </tr>

      </table>

      </td>

    </tr>

  </table>

  </center>

</div>



</body>



</html>
<?php
mysql_free_result($Recordset5);
?>
The last line is 282

feyd | switched

Code: Select all

into

Code: Select all

[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

In the quick walk I did through the code, I didn't see anything that'd create a parse error.

there is a few logic errors, query syntax errors, and a misplaced php end tag (?>), though..
Post Reply