[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 915
  • Last Modified:

mysql php query database with php

i have a web form that queries a mysql database the first webpage is a master page that display all of the database this works fine.


but when you click on the individual record to display that information i get

Warning: mysql_query() [function.mysql-query]: Unable to save result set in E:\xampp\htdocs\intranet\donttouch\456789.php on line 53

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\xampp\htdocs\intranet\donttouch\456789.php on line 54

it looks like there is something wrong with my query  the  server crashes

I am using xampp on a windows 2003 server
code for master page 
 
<?php require_once('../Connections/db521.php'); ?>
<?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;
}
}
 
$currentPage = $_SERVER["PHP_SELF"];
 
$maxRows_Recordset1 = 10;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;
 
mysql_select_db($database_db521, $db521);
$query_Recordset1 = "SELECT * FROM agency, client, obligee WHERE client.agencyid = agency.AgencyID  and obligee.clientid = client.ClientID ";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $db521) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
 
if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
 
$queryString_Recordset1 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_Recordset1") == false && 
        stristr($param, "totalRows_Recordset1") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_Recordset1 = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
<table border="1" align="center">
  <tr>
    <td>AgencyID</td>
    <td>AGENCY</td>
    <td>AGENT Address</td>
    <td>AGENT City</td>
    <td>AGENT FIRST</td>
    <td>AGENT St</td>
    <td>AGENT Zip</td>
    <td>AGENT MIDDLE</td>
    <td>AGENT LAST</td>
    <td>AGENT SUFF</td>
    <td>AGENT Phone</td>
    <td>AGENT Fax</td>
    <td>AGENTS EMAIL</td>
    <td>CLIENT NAME</td>
    <td>CLIENT Address</td>
    <td>CLIENT City</td>
    <td>CLIENT FIRST</td>
    <td>CLIENT St</td>
    <td>CLIENT Zip</td>
    <td>CLIENT MIDDLE</td>
    <td>CLIENT LAST</td>
    <td>CLIENT SUFF</td>
    <td>CLIENT PHONE</td>
    <td>CLIENT FAX</td>
    <td>CLIENTS EMAIL</td>
    <td>Field13</td>
    <td>date_created</td>
    <td>Obligee</td>
    <td>OBLIGEE ADDRESS</td>
    <td>OBLIGEE CITY</td>
    <td>OBLIGEE STATE</td>
    <td>OBLIGEE CONTACT</td>
    <td>OBLIGEE ZIP</td>
    <td>OBLIGEE FAX</td>
    <td>OBLIGEE PHONE</td>
    <td>ObligeeID</td>
    <td>OBLIGEE EMAIL</td>
    <td>ClientID</td>
  </tr>
  <?php do { ?>
    <tr>
      <td><a href="456789.php?recordID=<?php echo $row_Recordset1['ClientID']; ?>"> <?php echo $row_Recordset1['AgencyID']; ?>&nbsp; </a></td>
      <td><?php echo $row_Recordset1['AGENCY']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT Address']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT City']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT FIRST']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT St']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT Zip']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT MIDDLE']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT LAST']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT SUFF']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT Phone']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENT Fax']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['AGENTS EMAIL']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT NAME']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT Address']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT City']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT FIRST']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT St']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT Zip']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT MIDDLE']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT LAST']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT SUFF']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT PHONE']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENT FAX']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['CLIENTS EMAIL']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['Field13']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['date_created']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['Obligee']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE ADDRESS']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE CITY']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE STATE']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE CONTACT']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE ZIP']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE FAX']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE PHONE']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['ObligeeID']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['OBLIGEE EMAIL']; ?>&nbsp; </td>
      <td><?php echo $row_Recordset1['ClientID']; ?>&nbsp; </td>
    </tr>
    <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
</table>
<br />
<table border="0">
  <tr>
    <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, 0, $queryString_Recordset1); ?>">First</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Recordset1 > 0) { // Show if not first page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, max(0, $pageNum_Recordset1 - 1), $queryString_Recordset1); ?>">Previous</a>
        <?php } // Show if not first page ?></td>
    <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, min($totalPages_Recordset1, $pageNum_Recordset1 + 1), $queryString_Recordset1); ?>">Next</a>
        <?php } // Show if not last page ?></td>
    <td><?php if ($pageNum_Recordset1 < $totalPages_Recordset1) { // Show if not last page ?>
        <a href="<?php printf("%s?pageNum_Recordset1=%d%s", $currentPage, $totalPages_Recordset1, $queryString_Recordset1); ?>">Last</a>
        <?php } // Show if not last page ?></td>
  </tr>
</table>
Records <?php echo ($startRow_Recordset1 + 1) ?> to <?php echo min($startRow_Recordset1 + $maxRows_Recordset1, $totalRows_Recordset1) ?> of <?php echo $totalRows_Recordset1 ?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
 
end of of code for master page
 
detail of one record begines 
detail of page detail 
 
 
<?php require_once('../Connections/db521.php'); ?><?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;
}
}
 
$maxRows_DetailRS1 = 1;
$pageNum_DetailRS1 = 0;
if (isset($_GET['pageNum_DetailRS1'])) {
  $pageNum_DetailRS1 = $_GET['pageNum_DetailRS1'];
}
$startRow_DetailRS1 = $pageNum_DetailRS1 * $maxRows_DetailRS1;
 
$colname_DetailRS1 = "-1";
if (isset($_GET['recordID'])) {
  $colname_DetailRS1 = $_GET['recordID'];
}
mysql_select_db($database_db521, $db521);
$query_DetailRS1 = sprintf("SELECT * FROM agency, client, obligee WHERE client.ClientID=%s", GetSQLValueString($colname_DetailRS1, "int"));
$query_limit_DetailRS1 = sprintf("%s LIMIT %d, %d", $query_DetailRS1, $startRow_DetailRS1, $maxRows_DetailRS1);
$DetailRS1 = mysql_query($query_limit_DetailRS1, $db521) or die(mysql_error());
$row_DetailRS1 = mysql_fetch_assoc($DetailRS1);
 
if (isset($_GET['totalRows_DetailRS1'])) {
  $totalRows_DetailRS1 = $_GET['totalRows_DetailRS1'];
} else {
  $all_DetailRS1 = mysql_query($query_DetailRS1);
  $totalRows_DetailRS1 = mysql_num_rows($all_DetailRS1);
}
$totalPages_DetailRS1 = ceil($totalRows_DetailRS1/$maxRows_DetailRS1)-1;
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 
<table border="1" align="center">
  <tr>
    <td>AgencyID</td>
    <td><?php echo $row_DetailRS1['AgencyID']; ?></td>
  </tr>
  <tr>
    <td>AGENCY</td>
    <td><?php echo $row_DetailRS1['AGENCY']; ?></td>
  </tr>
  <tr>
    <td>AGENT Address</td>
    <td><?php echo $row_DetailRS1['AGENT Address']; ?></td>
  </tr>
  <tr>
    <td>AGENT City</td>
    <td><?php echo $row_DetailRS1['AGENT City']; ?></td>
  </tr>
  <tr>
    <td>AGENT FIRST</td>
    <td><?php echo $row_DetailRS1['AGENT FIRST']; ?></td>
  </tr>
  <tr>
    <td>AGENT St</td>
    <td><?php echo $row_DetailRS1['AGENT St']; ?></td>
  </tr>
  <tr>
    <td>AGENT Zip</td>
    <td><?php echo $row_DetailRS1['AGENT Zip']; ?></td>
  </tr>
  <tr>
    <td>AGENT MIDDLE</td>
    <td><?php echo $row_DetailRS1['AGENT MIDDLE']; ?></td>
  </tr>
  <tr>
    <td>AGENT LAST</td>
    <td><?php echo $row_DetailRS1['AGENT LAST']; ?></td>
  </tr>
  <tr>
    <td>AGENT SUFF</td>
    <td><?php echo $row_DetailRS1['AGENT SUFF']; ?></td>
  </tr>
  <tr>
    <td>AGENT Phone</td>
    <td><?php echo $row_DetailRS1['AGENT Phone']; ?></td>
  </tr>
  <tr>
    <td>AGENT Fax</td>
    <td><?php echo $row_DetailRS1['AGENT Fax']; ?></td>
  </tr>
  <tr>
    <td>AGENTS EMAIL</td>
    <td><?php echo $row_DetailRS1['AGENTS EMAIL']; ?></td>
  </tr>
  <tr>
    <td>ClientID</td>
    <td><?php echo $row_DetailRS1['ClientID']; ?></td>
  </tr>
  <tr>
    <td>CLIENT NAME</td>
    <td><?php echo $row_DetailRS1['CLIENT NAME']; ?></td>
  </tr>
  <tr>
    <td>CLIENT Address</td>
    <td><?php echo $row_DetailRS1['CLIENT Address']; ?></td>
  </tr>
  <tr>
    <td>CLIENT City</td>
    <td><?php echo $row_DetailRS1['CLIENT City']; ?></td>
  </tr>
  <tr>
    <td>CLIENT FIRST</td>
    <td><?php echo $row_DetailRS1['CLIENT FIRST']; ?></td>
  </tr>
  <tr>
    <td>CLIENT St</td>
    <td><?php echo $row_DetailRS1['CLIENT St']; ?></td>
  </tr>
  <tr>
    <td>CLIENT Zip</td>
    <td><?php echo $row_DetailRS1['CLIENT Zip']; ?></td>
  </tr>
  <tr>
    <td>CLIENT MIDDLE</td>
    <td><?php echo $row_DetailRS1['CLIENT MIDDLE']; ?></td>
  </tr>
  <tr>
    <td>CLIENT LAST</td>
    <td><?php echo $row_DetailRS1['CLIENT LAST']; ?></td>
  </tr>
  <tr>
    <td>CLIENT SUFF</td>
    <td><?php echo $row_DetailRS1['CLIENT SUFF']; ?></td>
  </tr>
  <tr>
    <td>CLIENT PHONE</td>
    <td><?php echo $row_DetailRS1['CLIENT PHONE']; ?></td>
  </tr>
  <tr>
    <td>CLIENT FAX</td>
    <td><?php echo $row_DetailRS1['CLIENT FAX']; ?></td>
  </tr>
  <tr>
    <td>CLIENTS EMAIL</td>
    <td><?php echo $row_DetailRS1['CLIENTS EMAIL']; ?></td>
  </tr>
  <tr>
    <td>Field13</td>
    <td><?php echo $row_DetailRS1['Field13']; ?></td>
  </tr>
  <tr>
    <td>date_created</td>
    <td><?php echo $row_DetailRS1['date_created']; ?></td>
  </tr>
  <tr>
    <td>Obligee</td>
    <td><?php echo $row_DetailRS1['Obligee']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE ADDRESS</td>
    <td><?php echo $row_DetailRS1['OBLIGEE ADDRESS']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE CITY</td>
    <td><?php echo $row_DetailRS1['OBLIGEE CITY']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE STATE</td>
    <td><?php echo $row_DetailRS1['OBLIGEE STATE']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE CONTACT</td>
    <td><?php echo $row_DetailRS1['OBLIGEE CONTACT']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE ZIP</td>
    <td><?php echo $row_DetailRS1['OBLIGEE ZIP']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE FAX</td>
    <td><?php echo $row_DetailRS1['OBLIGEE FAX']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE PHONE</td>
    <td><?php echo $row_DetailRS1['OBLIGEE PHONE']; ?></td>
  </tr>
  <tr>
    <td>ObligeeID</td>
    <td><?php echo $row_DetailRS1['ObligeeID']; ?></td>
  </tr>
  <tr>
    <td>OBLIGEE EMAIL</td>
    <td><?php echo $row_DetailRS1['OBLIGEE EMAIL']; ?></td>
  </tr>
  <tr>
    <td>ClientID</td>
    <td><?php echo $row_DetailRS1['ClientID']; ?></td>
  </tr>
</table>
</body>
</html><?php
mysql_free_result($DetailRS1);
?>

Open in new window

0
tomjenkins12
Asked:
tomjenkins12
2 Solutions
 
quincydudeCommented:
Try to run a repair DB in your mysql
0
 
tomjenkins12Author Commented:
i had to name the column names

agency.agencyig=colname1
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now