0 Replies Latest reply: Feb 6, 2012 12:40 PM by colonelswizz RSS

    Need to redirect to page if variable is not in the database

    colonelswizz Community Member

      I am pretty new to php so I just am just poking and prodding at this point.  I have built a page that uses url parameters that returns info based one 1 variable.  What I am trying to do is if the binding variable does not exist in the database I want to redirect to a page. 1) is this possible 2)If possible how can I do it?

       

      <?php

      if (!function_exists("GetSQLValueString")) {

      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

      {

        if (PHP_VERSION < 6) {

          $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

        }

       

       

        $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

       

       

        switch ($theType) {

          case "text":

            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

            break;   

          case "long":

          case "int":

            $theValue = ($theValue != "") ? intval($theValue) : "NULL";

            break;

          case "double":

            $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

            break;

          case "date":

            $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

            break;

          case "defined":

            $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

            break;

        }

        return $theValue;

      }

      }

      $colname_rsTour = "-1";

      if (isset($_GET['tourID'])) {

                $colname_rsTour = $_GET['tourID'];

       

       

      }

      mysql_select_db($database_hometours, $hometours);

      $query_rsTour = sprintf("SELECT property.tourId, property.address, property.price, agent.firstname,agent.lastname,property.beds, property.baths, property.sqft, property.mlsId, property.slidexml, dsrLink FROM property, agent WHERE property.tourId = %s AND property.agentId = agent.agentId ", GetSQLValueString($colname_rsTour, "int"));

      $rsTour = mysql_query($query_rsTour, $hometours) or die(mysql_error());

      $row_rsTour = mysql_fetch_assoc($rsTour);

      $totalRows_rsTour = mysql_num_rows($rsTour);

       

       

      mysql_free_result($rsTour);

      ?>

       

      SO basically if the tourID is not in the database I want to redirect to another page.

       

      Thanks in advance.