title: How can i Search using two variables in two different fields in MySQL
body: <p>This is the code that I have -- I can't make it work:</p>
  
  <pre><code>&lt;?php require_once('../Connections/User.php'); ?&gt;
  &lt;?php
  if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
  {
    if (PHP_VERSION &lt; 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;
  }
  }
  
  $editFormAction = $_SERVER['PHP_SELF'];
  if (isset($_SERVER['QUERY_STRING'])) {
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ((isset($_POST["MM_update"])) &amp;&amp; ($_POST["MM_update"] == "form1")) {
    $updateSQL = sprintf("UPDATE grade SET GSCode=%s, GSem=%s, GYear=%s, Grade=%s WHERE GStudNo=%s",
                         GetSQLValueString($_POST['GSCode'], "text"),
                         GetSQLValueString($_POST['GSem'], "text"),
                         GetSQLValueString($_POST['GYear'], "text"),
                         GetSQLValueString($_POST['Grade'], "text"),
                         GetSQLValueString($_POST['GStudNo'], "text"));
  
    mysql_select_db($database_User, $User);
    $Result1 = mysql_query($updateSQL, $User) or die(mysql_error());
  }
  
  mysql_select_db($database_User, $User);
  $query_Recordset1 = sprintf("SELECT * 
             FROM grade 
            WHERE GSCode = '%s' AND GStudNo = '%s'",
          mysql_real_escape_string($_POST['a']),
          mysql_real_escape_string($_POST['b']));
  
  $Recordset1 = mysql_query($query_Recordset1, $User) or die(mysql_error());
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  $query_Recordset1 = "SELECT * FROM grade WHERE GSCode = '$_POST[a]' $$ GStudNo =  '$_POST[b]'";
  $Recordset1 = mysql_query($query_Recordset1, $User) or die(mysql_error());
  $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;form action="&lt;?php echo $editFormAction; ?&gt;" method="post" name="form1" id="form1"&gt;
    &lt;table align="center"&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;GStudNo:&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $row_Recordset1['GStudNo']; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;GSCode:&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="GSCode" value="&lt;?php echo htmlentities($row_Recordset1['GSCode'], ENT_COMPAT, 'utf-8'); ?&gt;" size="32" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;GSem:&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="GSem" value="&lt;?php echo htmlentities($row_Recordset1['GSem'], ENT_COMPAT, 'utf-8'); ?&gt;" size="32" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;GYear:&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="GYear" value="&lt;?php echo htmlentities($row_Recordset1['GYear'], ENT_COMPAT, 'utf-8'); ?&gt;" size="32" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;Grade:&lt;/td&gt;
        &lt;td&gt;&lt;input type="text" name="Grade" value="&lt;?php echo htmlentities($row_Recordset1['Grade'], ENT_COMPAT, 'utf-8'); ?&gt;" size="32" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr valign="baseline"&gt;
        &lt;td nowrap="nowrap" align="right"&gt;&amp;nbsp;&lt;/td&gt;
        &lt;td&gt;&lt;input type="submit" value="Update record" /&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    &lt;input type="hidden" name="MM_update" value="form1" /&gt;
    &lt;input type="hidden" name="GStudNo" value="&lt;?php echo $row_Recordset1['GStudNo']; ?&gt;" /&gt;
  &lt;/form&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;?php
  mysql_free_result($Recordset1);
  ?&gt;
  </code></pre>