PHP Code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dyawlak
Forum Newbie
Posts: 1
Joined: Wed May 28, 2008 4:17 am

PHP Code

Post by dyawlak »

The code below was generated by the MS SQL PHP Generator, I also tried another generator to same effect.

The problem appears to be around the find functionality. Both generators find routine filters correctly. However, the functionality on both scripts for moving to another page, drops the filtering and returns page x of the over all list instead.

Any help appreciated..

Tried to attach code but couldn't find an extension that was allowed !

Block -10:

Code: Select all

 
<?php session_start(); ?>
<html>
<head>
<title>SW_Inv -- dbo.Software</title>
<meta name="generator" content="text/html; charset=ISO-8859-1">
<style type="text/css">
  body {
    background-color: #317676;
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #317676;
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  .tbl {
    background-color: #276262;
  }
  a:link { 
    color: #FFE760;
    font-family: Arial;
    font-size: 12px;
  }
  a:active { 
    color: #FFFF00;
    font-family: Arial;
    font-size: 12px;
  }
  a:visited { 
    color: #CCCC39;
    font-family: Arial;
    font-size: 12px;
  }
  .hr {
    background-color: #3A9393;
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:link {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:active {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  a.hr:visited {
    color: #FFFFFF;
    font-family: Arial;
    font-size: 12px;
  }
  .dr {
    background-color: #276262;
    color: #FFE760;
    font-family: Arial;
    font-size: 12px;
  }
  .sr {
    background-color: #367800;
    color: #FFE760;
    font-family: Arial;
    font-size: 12px;
  }
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>EC Harris DSL</h2></td></tr></table>
<?php
  $conn = connect();
  $showrecs = 50;
  $pagerange = 10;
 
  $a = @$_GET["a"];
  $recid = @$_GET["recid"];
  if (isset($_GET["order"])) $order = @$_GET["order"];
  if (isset($_GET["type"])) $ordtype = @$_GET["type"];
 
  if (isset($_POST["filter"])) $filter = @$_POST["filter"];
  if (isset($_POST["filter_field"])) $filterfield = @$_POST["filter_field"];
  $wholeonly = false;
  if (isset($_POST["wholeonly"])) $wholeonly = @$_POST["wholeonly"];
 
  if (!isset($order) && isset($_SESSION["order"])) $order = $_SESSION["order"];
  if (!isset($ordtype) && isset($_SESSION["type"])) $ordtype = $_SESSION["type"];
  if (!isset($filter) && isset($_SESSION["filter"])) $filter = $_SESSION["filter"];
  if (!isset($filterfield) && isset($_SESSION["filter_field"])) $filterfield = $_SESSION["filter_field"];
 
  $page = @$_GET["page"];
  if (!isset($page)) $page = 1;
 
  $sql = @$_POST["sql"];
 
  switch ($sql) {
    case "insert":
      sql_insert();
      break;
    case "update":
      sql_update();
      break;
  }
 
  switch ($a) {
    case "add":
      addrec();
      break;
    case "view":
      viewrec($recid);
      break;
    case "edit":
      editrec($recid);
      break;
    default:
      select();
      break;
  }
 
  if (isset($order)) $_SESSION["order"] = $order;
  if (isset($ordtype)) $_SESSION["type"] = $ordtype;
  if (isset($filter)) $_SESSION["filter"] = $filter;
  if (isset($filterfield)) $_SESSION["filter_field"] = $filterfield;
  if (isset($wholeonly)) $_SESSION["wholeonly"] = $wholeonly;
 
  mssql_close($conn);
?>
<table class="bd" width="100%"><tr><td class="hr">http://mantis.echarris.com/</td></tr></table>
</body>
</html>
 
Block -9:

Code: Select all

 
<?php function select()
  {
  global $a;
  global $showrecs;
  global $page;
  global $filter;
  global $filterfield;
  global $wholeonly;
  global $order;
  global $ordtype;
 
 
  if ($a == "reset") {
    $filter = "";
    $filterfield = "";
    $wholeonly = "";
    $order = "";
    $ordtype = "";
  }
 
  $checkstr = "";
  if ($wholeonly) $checkstr = " checked";
  if ($ordtype == "asc") { $ordtypestr = "desc"; } else { $ordtypestr = "asc"; }
  $res = sql_select();
  $count = sql_getrecordcount();
  if ($count % $showrecs != 0) {
    $pagecount = intval($count / $showrecs) + 1;
  }
  else {
    $pagecount = intval($count / $showrecs);
  }
  $startrec = $showrecs * ($page - 1);
  if ($startrec < $count) {mssql_data_seek($res, $startrec);}
  $reccount = min($showrecs * $page, $count);
  $fields = array(
    "ID" => "ID",
    "BOX" => "BOX",
    "CPX" => "CPX",
    "BU" => "BU",
    "Location" => "Location",
    "USER" => "USER",
    "Tag Nbr" => "Tag Nbr",
    "Manufacturer" => "Manufacturer",
    "PRODUCT NAME" => "PRODUCT NAME",
    "Ver#" => "Ver#",
    "SERIAL #" => "SERIAL #",
    "PRODUCT KEYS" => "PRODUCT KEYS",
    "Quantity" => "Quantity",
    "Checked Out" => "Checked Out",
    "Date Entered" => "Date Entered",
    "Notes" => "Notes");
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>DSL: dbo.Software</td></tr>
<tr><td>Records shown <?php echo $startrec + 1 ?> - <?php echo $reccount ?> of <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="dbo_Software.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Custom Filter</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">All Fields</option>
<?php
  reset($fields);
  foreach($fields as $val => $caption) {
    if ($val == $filterfield) {$selstr = " selected"; } else {$selstr = ""; }
?>
<option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo htmlspecialchars($caption) ?></option>
<?php } ?>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Whole words only</td>
</td></tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Apply Filter"></td>
<td><a href="dbo_Software.php?a=reset">Reset Filter</a></td>
</tr>
</table>
</form>
<hr size="1" noshade>
<?php showpagenav($page, $pagecount); ?>
<br>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="100%">
<tr>
<?php
  reset($fields);
  foreach($fields as $val => $caption) {
?>
<td class="hr"><a class="hr" href="dbo_Software.php?order=<?php echo $val ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars($caption) ?></a></td>
<?php } ?>
<td class="hr">&nbsp;</td>
<td class="hr">&nbsp;</td>
</tr>
<?php
  for ($i = $startrec; $i < $reccount; $i++)
  {
    $row = mssql_fetch_assoc($res);
    $style = "dr";
    if ($i % 2 != 0) {
      $style = "sr";
    }
?>
<tr>
<?php
  reset($fields);
  foreach($fields as $val => $caption) {
?>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row[$val]) ?></td>
<?php } ?>
<td class="<?php echo $style ?>"><a href="dbo_Software.php?a=view&recid=<?php echo $i ?>">View</a></td>
<td class="<?php echo $style ?>"><a href="dbo_Software.php?a=edit&recid=<?php echo $i ?>">Edit</a></td>
</tr>
<?php
  }
  mssql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>
 
Block -8:

Code: Select all

 
<?php function showrow($row)
  {
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("ID")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["ID"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BOX")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["BOX"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("CPX")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["CPX"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BU")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["BU"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Location")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Location"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("USER")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["USER"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Tag Nbr")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Tag Nbr"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Manufacturer")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Manufacturer"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PRODUCT NAME")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PRODUCT NAME"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Ver#")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Ver#"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("SERIAL #")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["SERIAL #"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PRODUCT KEYS")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["PRODUCT KEYS"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Quantity")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Quantity"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Checked Out")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Checked Out"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Date Entered")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Date Entered"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Notes")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Notes"]) ?></td>
</tr>
</table>
<?php } ?>
 
Block -7:

Code: Select all

 
<?php function showroweditor($row)
  {
  global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("ID")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="ID"><?php echo str_replace('"', '"', trim($row["ID"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BOX")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="BOX" maxlength="255"><?php echo str_replace('"', '"', trim($row["BOX"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("CPX")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="CPX" maxlength="255"><?php echo str_replace('"', '"', trim($row["CPX"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("BU")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="BU" maxlength="255"><?php echo str_replace('"', '"', trim($row["BU"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Location")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Location" maxlength="255"><?php echo str_replace('"', '"', trim($row["Location"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("USER")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="USER" maxlength="255"><?php echo str_replace('"', '"', trim($row["USER"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Tag Nbr")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Tag_Nbr" maxlength="10" value="<?php echo str_replace('"', '"', trim($row["Tag Nbr"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Manufacturer")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Manufacturer" maxlength="255"><?php echo str_replace('"', '"', trim($row["Manufacturer"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PRODUCT NAME")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="PRODUCT_NAME" maxlength="255"><?php echo str_replace('"', '"', trim($row["PRODUCT NAME"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Ver#")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Ver#" maxlength="255"><?php echo str_replace('"', '"', trim($row["Ver#"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("SERIAL #")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="SERIAL_#" maxlength="255"><?php echo str_replace('"', '"', trim($row["SERIAL #"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("PRODUCT KEYS")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="PRODUCT_KEYS" maxlength="255"><?php echo str_replace('"', '"', trim($row["PRODUCT KEYS"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Quantity")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Quantity" maxlength="255"><?php echo str_replace('"', '"', trim($row["Quantity"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Checked Out")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Checked_Out" maxlength="3" value="<?php echo str_replace('"', '"', trim($row["Checked Out"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Date Entered")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Date_Entered" value="<?php echo str_replace('"', '"', trim($row["Date Entered"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Notes")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Notes" maxlength="400"><?php echo str_replace('"', '"', trim($row["Notes"])) ?></textarea></td>
</tr>
</table>
<?php } ?>
 
Block -6:

Code: Select all

 
<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="dbo_Software.php?a=add">Add Record</a>&nbsp;</td>
<?php if ($page > 1) { ?>
<td><a href="dbo_Software.php?page=<?php echo $page - 1 ?>"><<&nbsp;Prev</a>&nbsp;</td>
<?php } ?>
<?php
  global $pagerange;
 
  if ($pagecount > 1) {
 
  if ($pagecount % $pagerange != 0) {
    $rangecount = intval($pagecount / $pagerange) + 1;
  }
  else {
    $rangecount = intval($pagecount / $pagerange);
  }
  for ($i = 1; $i < $rangecount + 1; $i++) {
    $startpage = (($i - 1) * $pagerange) + 1;
    $count = min($i * $pagerange, $pagecount);
 
    if ((($page >= $startpage) && ($page <= ($i * $pagerange)))) {
      for ($j = $startpage; $j < $count + 1; $j++) {
        if ($j == $page) {
?>
<td><b><?php echo $j ?></b></td>
<?php } else { ?>
<td><a href="dbo_Software.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="dbo_Software.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="dbo_Software.php?page=<?php echo $page + 1 ?>">Next&nbsp;>></a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>
 
Block -5:

Code: Select all

 
<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="dbo_Software.php">Index Page</a></td>
<?php if ($recid > 0) { ?>
<td><a href="dbo_Software.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Prior Record</a></td>
<?php } if ($recid < $count) { ?>
<td><a href="dbo_Software.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Next Record</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>
 
Block -4:

Code: Select all

 
<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="dbo_Software.php">Index Page</a></td>
</tr>
</table>
<hr size="1" noshade>
<form action="dbo_Software.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "ID" => "",
  "BOX" => "",
  "CPX" => "",
  "BU" => "",
  "Location" => "",
  "USER" => "",
  "Tag Nbr" => "",
  "Manufacturer" => "",
  "PRODUCT NAME" => "",
  "Ver#" => "",
  "SERIAL #" => "",
  "PRODUCT KEYS" => "",
  "Quantity" => "",
  "Checked Out" => "",
  "Date Entered" => "",
  "Notes" => "");
showroweditor($row)
?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php } ?>
 
Block -3:

Code: Select all

 
<?php function viewrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mssql_data_seek($res, $recid);
  $row = mssql_fetch_assoc($res);
  showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="dbo_Software.php?a=add">Add Record</a></td>
<td><a href="dbo_Software.php?a=edit&recid=<?php echo $recid ?>">Edit Record</a></td>
</tr>
</table>
<?php
  mssql_free_result($res);
} ?>
 
Block -2:

Code: Select all

 
<?php function editrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mssql_data_seek($res, $recid);
  $row = mssql_fetch_assoc($res);
  showrecnav("edit", $recid, $count);
?>
<br>
<form action="dbo_Software.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xID" value="<?php echo $row["ID"] ?>">
<input type="hidden" name="xBOX" value="<?php echo $row["BOX"] ?>">
<input type="hidden" name="xCPX" value="<?php echo $row["CPX"] ?>">
<input type="hidden" name="xBU" value="<?php echo $row["BU"] ?>">
<input type="hidden" name="xLocation" value="<?php echo $row["Location"] ?>">
<input type="hidden" name="xUSER" value="<?php echo $row["USER"] ?>">
<input type="hidden" name="xTag Nbr" value="<?php echo $row["Tag Nbr"] ?>">
<input type="hidden" name="xManufacturer" value="<?php echo $row["Manufacturer"] ?>">
<input type="hidden" name="xPRODUCT NAME" value="<?php echo $row["PRODUCT NAME"] ?>">
<input type="hidden" name="xVer#" value="<?php echo $row["Ver#"] ?>">
<input type="hidden" name="xSERIAL #" value="<?php echo $row["SERIAL #"] ?>">
<input type="hidden" name="xPRODUCT KEYS" value="<?php echo $row["PRODUCT KEYS"] ?>">
<input type="hidden" name="xQuantity" value="<?php echo $row["Quantity"] ?>">
<input type="hidden" name="xChecked Out" value="<?php echo $row["Checked Out"] ?>">
<input type="hidden" name="xDate Entered" value="<?php echo $row["Date Entered"] ?>">
<input type="hidden" name="xNotes" value="<?php echo $row["Notes"] ?>">
<?php showroweditor($row) ?>
<p><input type="submit" name="action" value="Post"></p>
</form>
<?php
  mssql_free_result($res);
} ?>
 
Block -1:

Code: Select all

 
<?php function connect()
{
  $conn = mssql_connect("server", "x", "x");
  mssql_select_db("SW_Inv");
  return $conn;
}
 
function sqlvalue($val, $quote)
{
  if ($quote)
    $tmp = sqlstr($val);
  else
    $tmp = $val;
  if ($tmp == "")
    $tmp = "NULL";
  elseif ($quote)
    $tmp = "'".$tmp."'";
  return $tmp;
}
 
function sqlstr($val)
{
  return str_replace("'", "''", $val);
}
 
function sql_select()
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;
 
  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "select ID, BOX, CPX, BU, Location, [USER], [Tag Nbr], Manufacturer, [PRODUCT NAME], Ver#, [SERIAL #], [PRODUCT KEYS], Quantity, [Checked Out], [Date Entered], Notes from dbo.Software";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (ID like '" .$filterstr ."') or (BOX like '" .$filterstr ."') or (CPX like '" .$filterstr ."') or (BU like '" .$filterstr ."') or (Location like '" .$filterstr ."') or ([USER] like '" .$filterstr ."') or ([Tag Nbr] like '" .$filterstr ."') or (Manufacturer like '" .$filterstr ."') or ([PRODUCT NAME] like '" .$filterstr ."') or (Ver# like '" .$filterstr ."') or ([SERIAL #] like '" .$filterstr ."') or ([PRODUCT KEYS] like '" .$filterstr ."') or (Quantity like '" .$filterstr ."') or ([Checked Out] like '" .$filterstr ."') or ([Date Entered] like '" .$filterstr ."') or (Notes like '" .$filterstr ."')";
  }
  if (isset($order) && $order!='') $sql .= " order by \"" .sqlstr($order) ."\"";
  if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
  $res = mssql_query($sql, $conn);
  return $res;
}
 
function sql_getrecordcount()
{
  global $conn;
  global $order;
  global $ordtype;
  global $filter;
  global $filterfield;
  global $wholeonly;
 
  $filterstr = sqlstr($filter);
  if (!$wholeonly && isset($wholeonly) && $filterstr!='') $filterstr = "%" .$filterstr ."%";
  $sql = "select count(*) from dbo.Software";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (ID like '" .$filterstr ."') or (BOX like '" .$filterstr ."') or (CPX like '" .$filterstr ."') or (BU like '" .$filterstr ."') or (Location like '" .$filterstr ."') or ([USER] like '" .$filterstr ."') or ([Tag Nbr] like '" .$filterstr ."') or (Manufacturer like '" .$filterstr ."') or ([PRODUCT NAME] like '" .$filterstr ."') or (Ver# like '" .$filterstr ."') or ([SERIAL #] like '" .$filterstr ."') or ([PRODUCT KEYS] like '" .$filterstr ."') or (Quantity like '" .$filterstr ."') or ([Checked Out] like '" .$filterstr ."') or ([Date Entered] like '" .$filterstr ."') or (Notes like '" .$filterstr ."')";
  }
  $res = mssql_query($sql, $conn);
  $row = mssql_fetch_assoc($res);
  reset($row);
  return current($row);
}
 
function sql_insert()
{
  global $conn;
  global $_POST;
 
  $sql = "insert into dbo.Software (ID, BOX, CPX, BU, Location, [USER], [Tag Nbr], Manufacturer, [PRODUCT NAME], Ver#, [SERIAL #], [PRODUCT KEYS], Quantity, [Checked Out], [Date Entered], Notes) values (" .sqlvalue(@$_POST["ID"], false) .", " .sqlvalue(@$_POST["BOX"], true) .", " .sqlvalue(@$_POST["CPX"], true) .", " .sqlvalue(@$_POST["BU"], true) .", " .sqlvalue(@$_POST["Location"], true) .", " .sqlvalue(@$_POST["USER"], true) .", " .sqlvalue(@$_POST["Tag_Nbr"], true) .", " .sqlvalue(@$_POST["Manufacturer"], true) .", " .sqlvalue(@$_POST["PRODUCT_NAME"], true) .", " .sqlvalue(@$_POST["Ver#"], true) .", " .sqlvalue(@$_POST["SERIAL_#"], true) .", " .sqlvalue(@$_POST["PRODUCT_KEYS"], true) .", " .sqlvalue(@$_POST["Quantity"], true) .", " .sqlvalue(@$_POST["Checked_Out"], true) .", " .sqlvalue(@$_POST["Date_Entered"], true) .", " .sqlvalue(@$_POST["Notes"], true) .")";
  mssql_query($sql, $conn);
}
 
function sql_update()
{
  global $conn;
  global $_POST;
 
  $sql = "update dbo.Software set ID=" .sqlvalue(@$_POST["ID"], false) .", BOX=" .sqlvalue(@$_POST["BOX"], true) .", CPX=" .sqlvalue(@$_POST["CPX"], true) .", BU=" .sqlvalue(@$_POST["BU"], true) .", Location=" .sqlvalue(@$_POST["Location"], true) .", [USER]=" .sqlvalue(@$_POST["USER"], true) .", [Tag Nbr]=" .sqlvalue(@$_POST["Tag_Nbr"], true) .", Manufacturer=" .sqlvalue(@$_POST["Manufacturer"], true) .", [PRODUCT NAME]=" .sqlvalue(@$_POST["PRODUCT_NAME"], true) .", Ver#=" .sqlvalue(@$_POST["Ver#"], true) .", [SERIAL #]=" .sqlvalue(@$_POST["SERIAL_#"], true) .", [PRODUCT KEYS]=" .sqlvalue(@$_POST["PRODUCT_KEYS"], true) .", Quantity=" .sqlvalue(@$_POST["Quantity"], true) .", [Checked Out]=" .sqlvalue(@$_POST["Checked_Out"], true) .", [Date Entered]=" .sqlvalue(@$_POST["Date_Entered"], true) .", Notes=" .sqlvalue(@$_POST["Notes"], true) ." where " ."(ID=" .sqlvalue(@$_POST["xID"], false) .") and (BOX=" .sqlvalue(@$_POST["xBOX"], true) .") and (CPX=" .sqlvalue(@$_POST["xCPX"], true) .") and (BU=" .sqlvalue(@$_POST["xBU"], true) .") and (Location=" .sqlvalue(@$_POST["xLocation"], true) .") and ([USER]=" .sqlvalue(@$_POST["xUSER"], true) .") and ([Tag Nbr]=" .sqlvalue(@$_POST["xTag_Nbr"], true) .") and (Manufacturer=" .sqlvalue(@$_POST["xManufacturer"], true) .") and ([PRODUCT NAME]=" .sqlvalue(@$_POST["xPRODUCT_NAME"], true) .") and (Ver#=" .sqlvalue(@$_POST["xVer#"], true) .") and ([SERIAL #]=" .sqlvalue(@$_POST["xSERIAL_#"], true) .") and ([PRODUCT KEYS]=" .sqlvalue(@$_POST["xPRODUCT_KEYS"], true) .") and (Quantity=" .sqlvalue(@$_POST["xQuantity"], true) .") and ([Checked Out]=" .sqlvalue(@$_POST["xChecked_Out"], true) .") and ([Date Entered]=" .sqlvalue(@$_POST["xDate_Entered"], true) .") and (Notes=" .sqlvalue(@$_POST["xNotes"], true) .")";
  mssql_query($sql, $conn);
} ?>
Last edited by RobertGonzalez on Wed May 28, 2008 1:52 pm, edited 5 times in total.
Reason: Use code tags. Editing the original to test something.
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: PHP Code

Post by panic! »

What exactly is 'the problem'?.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: PHP Code

Post by onion2k »

panic! wrote:What exactly is 'the problem'?.
He's using a rubbish code generator.

:twisted:
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: PHP Code

Post by panic! »

well, there is that yes..haha. :D
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Code

Post by RobertGonzalez »

I am locking this topic temporarily whilst I troubleshoot a small problem with our bbCode tag parser. You might notice the original post changing (or even vanishing). Rest assured I have it backed up.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: PHP Code

Post by RobertGonzalez »

Sorry for breaking up the first post. It has to be that way for the moment.

This thread is now opened up again. Carry on.
Post Reply