skarni 0 Newbie Poster

Currently I am trying to get a php script I wrote with the help of a programmer friend to work in a content management system page. After countless hours trying to study why the CMS is not working, I've determined that there must be something wrong with my php code. The code somehow breaks the stylesheet for the page, leaving no footer and most of the graphics and layout elements gone.

I have debug mode enabled, so if your curious take a look.

Goto: http://www.caneycreekchurch.com/index.php?page=where-to-eat-at

select any location or type dropdown.

click submit.

The page breaks, and I have a ton of "Notice: Use of undefined constant.." errors. I am assuming this is why my page breaks.

Anyhow, the code I am using is the following, with sensitive info changed for my protection:

function db_connect()

    {

     

      $db= mysql_pconnect("database.db.hostedresource.com","wheretoeatdb","pass");   

      if (!db)

       {echo 'Unable to open database';exit;}

      else {

        mysql_select_db("wheretoeatdb");

      }   

    }







    function db_close()

    {

      mysql_close($db); 

    } 



    function getRestByName($name)

    {

    db_connect();

    //$query='select * from `eat` where name LIKE \'%'.addslashes($name).'%\'';
    $query= 'select distinct e.* ';
    $query.='from eat e ';
    $query.='left join eat_keyword ek on e.id = ek.eat_id ';
    $query.='where ek.keyword like \'%'.addslashes($name).'%\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          //echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";       

      echo '<img src=\''.$data[imgpath].'\'>';
     
      echo 'map='.$data[map]."";
           

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

         

      //return $str;

      //db_close(); 

    }

    function getRestByAll($name,$type,$location)

    {

      db_connect();

    $query= 'select distinct e.* ';
    $query.='from eat e ';
    $query.='left join eat_keyword ek on e.id = ek.eat_id ';
    $query.='where ek.keyword like \'%'.addslashes($name).'%\' ';
    $query.='AND e.type LIKE \'%'.$type.'%\' AND e.location = \''.$location.'\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";             

      echo '<img src=\''.$data[imgpath].'\'>'; 

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

    }

    function getRestByEither($type,$location)

    {

      db_connect();

    $query='select * from `eat` where type LIKE \'%'.$type.'%\' AND location = \''.$location.'\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";             

      echo '<img src=\''.$data[imgpath].'\'>'; 

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

    }

    function getRestByLocation($location)

    {

    db_connect();

    $query='select * from `eat` where location = \''.$location.'\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";       

      echo '<img src=\''.$data[imgpath].'\'>';     

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

         

      //return $str;

      //db_close(); 

    }


    function getRestByBoth($name,$type)

    {

      db_connect();

    $query= 'select distinct e.* ';
    $query.='from eat e ';
    $query.='left join eat_keyword ek on e.id = ek.eat_id ';
    $query.='where ek.keyword like \'%'.addslashes($name).'%\' ';
    $query.='AND e.type LIKE \'%'.$type.'%\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";             

      echo '<img src=\''.$data[imgpath].'\'>'; 

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

    }

    function getRestByNameLoc($name,$location)

    {

      db_connect();

    $query= 'select distinct e.* ';
    $query.='from eat e ';
    $query.='left join eat_keyword ek on e.id = ek.eat_id ';
    $query.='where ek.keyword like \'%'.addslashes($name).'%\' ';
    $query.='AND e.location = \''.$location.'\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";             

      echo '<img src=\''.$data[imgpath].'\'>'; 

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

    }


    function getRestByType($type)

    {

      db_connect();

    $query='select * from `eat` where type LIKE \'%'.$type.'%\'';

    echo $query.'<br>';

     

      @ $result=mysql_query($query);

      if (!$result)

      {   

      $problem=mysql_error();

      echo 'The following error occured  '.$problem;

      }

    else

      { 

       

      $numresults=mysql_num_rows($result);

      echo '<br><br>numresults='.$numresults.'<br><br>';

        for($x=1;$x<=$numresults;$x++)

          {

          $data=mysql_fetch_array($result);

          echo 'id='.$data[id]."<br>";

          echo 'name='.$data[name]."<br>";

          echo 'address='.$data[address]."<br>";

      echo 'city='.$data[city]."<br>";

          echo 'type='.$data[type]."<br>";             

      echo '<img src=\''.$data[imgpath].'\'>'; 

      echo "<br><br>";

          }

          //$str=$id.'|'.$date.'|'.$title.'|'.$entry;

      }

         

      //return $str;

      //db_close(); 

    }


      foreach($_POST as $key=>$value)

        echo $key."=".$value."<br>";

    if($_POST["restname"]!="" && $_POST["resttype"]=="" && $_POST["restlocation"]=="")

    {

        getRestByName($_POST["restname"]);

    exit;

    }

    if($_POST["restname"]=="" && $_POST["resttype"]=="" && $_POST["restlocation"]!="")

    {

        getRestByLocation($_POST["restlocation"]);

    exit;

    }

    if($_POST["restname"]=="" && $_POST["resttype"]!="" && $_POST["restlocation"]=="")

    { 

        getRestByType($_POST["resttype"]);

    exit;

    }

    if($_POST["restname"]!="" && $_POST["resttype"]!="" && $_POST["restlocation"]!="")

    { 

        getRestByAll($_POST["restname"],$_POST["resttype"],$_POST["restlocation"]);

    exit;

    }

    if($_POST["restname"]!="" && $_POST["resttype"]!="" && $_POST["restlocation"]=="")

    {

        getRestByBoth($_POST["restname"],$_POST["resttype"]);

    exit;

    }

      if($_POST["restname"]=="" && $_POST["resttype"]!="" && $_POST["restlocation"]!="")

    {


        getRestByEither($_POST["resttype"],$_POST["restlocation"]);

    exit;

    }

      if($_POST["restname"]!="" && $_POST["resttype"]=="" && $_POST["restlocation"]!="")

    {

        getRestByNameLoc($_POST["restname"],$_POST["restlocation"]);

    exit;

    }

I am very novice with php, so any rudimentary help would be appreciated. Thank you all for your help.

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.