Foros del Web » Programando para Internet » PHP »

mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index

Estas en el tema de mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index en el foro de PHP en Foros del Web. Muy buenos dias, es mi primer tema y mi mi primera. Tratare de explicarme lo mejor que pueda. Estoy comenzando a trabajar con php y ...
  #1 (permalink)  
Antiguo 11/05/2011, 07:48
 
Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años
Puntos: 0
mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index

Muy buenos dias, es mi primer tema y mi mi primera. Tratare de explicarme lo mejor que pueda.
Estoy comenzando a trabajar con php y me toca hacer un proyecto el cual permita bajar y subir archivos pdf y ya logre hacer la parte de subirlos pero no tengo idea de como bajarlos trate usando parte de un codigo de una guia pero me bota el sugiente error:
Warning: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL result index 3 in C:\AppServ\www\programa.php on line 617
a continuacion dejo el codigo esperando me puedan ayudar gracias de antemano.
  #2 (permalink)  
Antiguo 11/05/2011, 07:49
 
Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años
Puntos: 0
Respuesta: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL r

Código:
<?php session_start();
  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"];

  if (isset($_GET["getimage"]))
  {
    $conn = connect();
    getimage(@$_GET["getimage"], @$_GET["field"]);
    exit;
  }
?>

<html>
<head>
<title>dae -- programa</title>
<meta name="generator" http-equiv="content-type" content="text/html">
<style type="text/css">
  body {
    background-color: #FFFFFF;
    color: #004080;
    font-family: Arial;
    font-size: 12px;
  }
  .bd {
    background-color: #FFFFFF;
    color: #004080;
    font-family: Arial;
    font-size: 12px;
  }
  .tbl {
    background-color: #FFFFFF;
  }
  a:link { 
    color: #FF0000;
    font-family: Arial;
    font-size: 12px;
  }
  a:active { 
    color: #0000FF;
    font-family: Arial;
    font-size: 12px;
  }
  a:visited { 
    color: #800080;
    font-family: Arial;
    font-size: 12px;
  }
  .hr {
    background-color: #336699;
    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: #FFFFFF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
  .sr {
    background-color: #FFFFCF;
    color: #000000;
    font-family: Arial;
    font-size: 12px;
  }
</style>
</head>
<body>
<table class="bd" width="100%"><tr><td class="hr"><h2>Programas</h2></td></tr></table>
<?php
  $conn = connect();
  $showrecs = 10;
  $pagerange = 10;

  $a = @$_GET["a"];
  $recid = @$_GET["recid"];
  $page = @$_GET["page"];
  if (!isset($page)) $page = 1;

  $sql = @$_POST["sql"];

  switch ($sql) {
    case "insert":
      sql_insert();
      break;
    case "update":
      sql_update();
      break;
    case "delete":
      sql_delete();
      break;
  }

  switch ($a) {
    case "add":
      addrec();
      break;
    case "view":
      viewrec($recid);
      break;
    case "edit":
      editrec($recid);
      break;
    case "del":
      deleterec($recid);
      break;
    case "bajar":
      bajarp($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;

  mysql_close($conn);
?>

</body>
</html>

<?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) {mysql_data_seek($res, $startrec);}
  $reccount = min($showrecs * $page, $count);
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr><td>Tabla: programa</td></tr>
<tr><td>Programas Mostrados <?php echo $startrec + 1 ?> - <?php echo $reccount ?> de <?php echo $count ?></td></tr>
</table>
<hr size="1" noshade>
<form action="programa.php" method="post">
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><b>Filtro</b>&nbsp;</td>
<td><input type="text" name="filter" value="<?php echo $filter ?>"></td>
<td><select name="filter_field">
<option value="">Todos los campos</option>
<option value="<?php echo "Clave" ?>"<?php if ($filterfield == "Clave") { echo "selected"; } ?>><?php echo htmlspecialchars("Clave") ?></option>
<option value="<?php echo "Asignatura" ?>"<?php if ($filterfield == "Asignatura") { echo "selected"; } ?>><?php echo htmlspecialchars("Asignatura") ?></option>
<option value="<?php echo "Escuela" ?>"<?php if ($filterfield == "Escuela") { echo "selected"; } ?>><?php echo htmlspecialchars("Escuela") ?></option>
<option value="<?php echo "Nivel" ?>"<?php if ($filterfield == "Nivel") { echo "selected"; } ?>><?php echo htmlspecialchars("Nivel") ?></option>
<option value="<?php echo "Inicio" ?>"<?php if ($filterfield == "Inicio") { echo "selected"; } ?>><?php echo htmlspecialchars("Inicio") ?></option>
<option value="<?php echo "Fin" ?>"<?php if ($filterfield == "Fin") { echo "selected"; } ?>><?php echo htmlspecialchars("Fin") ?></option>
</select></td>
<td><input type="checkbox" name="wholeonly"<?php echo $checkstr ?>>Palabra completa</td>
</td></tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="action" value="Filtrar"></td>
<td><a href="programa.php?a=reset">Resetear Filro</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>
<td class="hr">&nbsp;</td>
<td class="hr">&nbsp;</td>
<td class="hr">&nbsp;</td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Clave" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Clave") ?></a></td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Asignatura" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Asignatura") ?></a></td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Escuela" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Escuela") ?></a></td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Nivel" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Nivel") ?></a></td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Inicio" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Inicio") ?></a></td>
<td class="hr"><a class="hr" href="programa.php?order=<?php echo "Fin" ?>&type=<?php echo $ordtypestr ?>"><?php echo htmlspecialchars("Fin") ?></a></td>
<td class="hr"><?php echo "Archivo" ?></td>
</tr>
<?php
  for ($i = $startrec; $i < $reccount; $i++)
  {
    $row = mysql_fetch_assoc($res);
    $style = "dr";
    if ($i % 2 != 0) {
      $style = "sr";
    }
?>
<tr>
<td class="<?php echo $style ?>"><a href="programa.php?a=view&recid=<?php echo $i ?>">Ver</a></td>
<td class="<?php echo $style ?>"><a href="programa.php?a=edit&recid=<?php echo $i ?>">Modificar</a></td>
<td class="<?php echo $style ?>"><a href="programa.php?a=del&recid=<?php echo $i ?>">Borrar</a></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Clave"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Asignatura"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Escuela"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Nivel"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Inicio"]) ?></td>
<td class="<?php echo $style ?>"><?php echo htmlspecialchars($row["Fin"]) ?></td>
<td class="<?php echo $style ?>"><a href="programa.php?a=bajar&recid=<?php echo $i ?>">Bajar</a></td>


</tr>
<?php
  }
  mysql_free_result($res);
?>
</table>
<br>
<?php showpagenav($page, $pagecount); ?>
<?php } ?>

<?php function showrow($row, $recid)
  {
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Clave")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Clave"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Asignatura")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Asignatura"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Escuela")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Escuela"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Nivel"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Inicio")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Inicio"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Fin")."&nbsp;" ?></td>
<td class="dr"><?php echo htmlspecialchars($row["Fin"]) ?></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Archivo")."&nbsp;" ?></td>
<td class="dr"><?php echo outimage($recid, "Archivo", "", "", "") ?></td>
</tr>
</table>
<?php } ?>


 ?>
continua...
  #3 (permalink)  
Antiguo 11/05/2011, 07:53
 
Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años
Puntos: 0
Respuesta: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL r

Código:
<?php function showroweditor($row, $iseditmode)
  {
  global $conn;
?>
<table class="tbl" border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td class="hr"><?php echo htmlspecialchars("Clave")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Clave" maxlength="20" value="<?php echo str_replace('"', '&quot;', trim($row["Clave"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Asignatura")."&nbsp;" ?></td>
<td class="dr"><textarea cols="35" rows="4" name="Asignatura" maxlength="100"><?php echo str_replace('"', '&quot;', trim($row["Asignatura"])) ?></textarea></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Escuela")."&nbsp;" ?></td>
<td class="dr"><select name="Escuela">
<?php
  $lookupvalues = array("Bioanalisis","Enfermeria","Medicina");

  reset($lookupvalues);
  foreach($lookupvalues as $val){
  $caption = $val;
  if ($row["Escuela"] == $val) {$selstr = " selected"; } else {$selstr = ""; }
 ?><option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
<?php } ?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Nivel")."&nbsp;" ?></td>
<td class="dr"><select name="Nivel">
<?php
  $lookupvalues = array("1er Ano","2do Ano","3er Ano","4to Ano","5to Ano");

  reset($lookupvalues);
  foreach($lookupvalues as $val){
  $caption = $val;
  if ($row["Nivel"] == $val) {$selstr = " selected"; } else {$selstr = ""; }
 ?><option value="<?php echo $val ?>"<?php echo $selstr ?>><?php echo $caption ?></option>
<?php } ?></select>
</td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Inicio")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Inicio" value="<?php echo str_replace('"', '&quot;', trim($row["Inicio"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Fin")."&nbsp;" ?></td>
<td class="dr"><input type="text" name="Fin" value="<?php echo str_replace('"', '&quot;', trim($row["Fin"])) ?>"></td>
</tr>
<tr>
<td class="hr"><?php echo htmlspecialchars("Archivo")."&nbsp;" ?></td>
<td class="dr">
<?php if ($iseditmode)
{
?> <input type="radio" name="a_Archivo" id="a_Archivo" value="1" checked>Keep&nbsp;
<input type="radio" name="a_Archivo" id="a_Archivo" value="2">Remove&nbsp;
<input type="radio" name="a_Archivo" id="a_Archivo" value="3">Replace<br>
<?php }
?> <input type="file" name="x_Archivo" id="x_Archivo" size="30" onChange="if (this.form.a_Archivo[2]) this.form.a_Archivo[2].checked=true;" >
</td>
</tr>
</table>
<?php } ?>

<?php function showpagenav($page, $pagecount)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php?a=add">Agregar Programa</a>&nbsp;</td>
<?php if ($page > 1) { ?>
<td><a href="programa.php?page=<?php echo $page - 1 ?>">&lt;&lt;&nbsp;Anterior</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="programa.php?page=<?php echo $j ?>"><?php echo $j ?></a></td>
<?php } } } else { ?>
<td><a href="programa.php?page=<?php echo $startpage ?>"><?php echo $startpage ."..." .$count ?></a></td>
<?php } } } ?>
<?php if ($page < $pagecount) { ?>
<td>&nbsp;<a href="programa.php?page=<?php echo $page + 1 ?>">Siguiente&nbsp;&gt;&gt;</a>&nbsp;</td>
<?php } ?>
</tr>
</table>
<?php } ?>

<?php function showrecnav($a, $recid, $count)
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php">Inicio</a></td>
<?php if ($recid > 0) { ?>
<td><a href="programa.php?a=<?php echo $a ?>&recid=<?php echo $recid - 1 ?>">Programa Anterior</a></td>
<?php } if ($recid < $count - 1) { ?>
<td><a href="programa.php?a=<?php echo $a ?>&recid=<?php echo $recid + 1 ?>">Siguiente Programa</a></td>
<?php } ?>
</tr>
</table>
<hr size="1" noshade>
<?php } ?>

<?php function addrec()
{
?>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php">Inicio</a></td>
</tr>
</table>
<hr size="1" noshade>
<form enctype="multipart/form-data" action="programa.php" method="post">
<p><input type="hidden" name="sql" value="insert"></p>
<?php
$row = array(
  "id" => "",
  "Clave" => "",
  "Asignatura" => "",
  "Escuela" => "",
  "Nivel" => "",
  "Inicio" => "",
  "Fin" => "");
showroweditor($row, false);
?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php } ?>

<?php function viewrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("view", $recid, $count);
?>
<br>
<?php showrow($row, $recid) ?>
<br>
<hr size="1" noshade>
<table class="bd" border="0" cellspacing="1" cellpadding="4">
<tr>
<td><a href="programa.php?a=add">Agregar Programa</a></td>
<td><a href="programa.php?a=edit&recid=<?php echo $recid ?>">Modificar</a></td>
<td><a href="programa.php?a=del&recid=<?php echo $recid ?>">Borrar</a></td>
</tr>
</table>
<?php
  mysql_free_result($res);
} ?>

<?php function editrec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("edit", $recid, $count);
?>
<br>
<form enctype="multipart/form-data" action="programa.php" method="post">
<input type="hidden" name="sql" value="update">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showroweditor($row, true); ?>
<p><input type="submit" name="action" value="Guardar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function deleterec($recid)
{
  $res = sql_select();
  $count = sql_getrecordcount();
  mysql_data_seek($res, $recid);
  $row = mysql_fetch_assoc($res);
  showrecnav("del", $recid, $count);
?>
<br>
<form action="programa.php" method="post">
<input type="hidden" name="sql" value="delete">
<input type="hidden" name="xid" value="<?php echo $row["id"] ?>">
<?php showrow($row, $recid) ?>
<p><input type="submit" name="action" value="Confirmar"></p>
</form>
<?php
  mysql_free_result($res);
} ?>

<?php function connect()
{
  $conn = mysql_connect("localhost", "root", "123456");
  mysql_select_db("dae");
  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`, `Clave`, `Asignatura`, `Escuela`, `Nivel`, `Inicio`, `Fin`, `Archivo` FROM `programa`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`Clave` like '" .$filterstr ."') or (`Asignatura` like '" .$filterstr ."') or (`Escuela` like '" .$filterstr ."') or (`Nivel` like '" .$filterstr ."') or (`Inicio` like '" .$filterstr ."') or (`Fin` like '" .$filterstr ."') or (`Archivo` like '" .$filterstr ."')";
  }
  if (isset($order) && $order!='') $sql .= " order by `" .sqlstr($order) ."`";
  if (isset($ordtype) && $ordtype!='') $sql .= " " .sqlstr($ordtype);
  $res = mysql_query($sql, $conn) or die(mysql_error());
  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 `programa`";
  if (isset($filterstr) && $filterstr!='' && isset($filterfield) && $filterfield!='') {
    $sql .= " where " .sqlstr($filterfield) ." like '" .$filterstr ."'";
  } elseif (isset($filterstr) && $filterstr!='') {
    $sql .= " where (`Clave` like '" .$filterstr ."') or (`Asignatura` like '" .$filterstr ."') or (`Escuela` like '" .$filterstr ."') or (`Nivel` like '" .$filterstr ."') or (`Inicio` like '" .$filterstr ."') or (`Fin` like '" .$filterstr ."') or (`Archivo` like '" .$filterstr ."')";
  }
  $res = mysql_query($sql, $conn) or die(mysql_error());
  $row = mysql_fetch_assoc($res);
  reset($row);
  return current($row);
}
continua..
  #4 (permalink)  
Antiguo 11/05/2011, 07:55
 
Fecha de Ingreso: mayo-2011
Mensajes: 4
Antigüedad: 13 años
Puntos: 0
Respuesta: mysql_result() [function.mysql-result]: Unable to jump to row 0 on MySQL r

Código:
function sql_insert()
{
  global $conn;
  global $_POST;

  $sql = "insert into `programa` (`id`, `Clave`, `Asignatura`, `Escuela`, `Nivel`, `Inicio`, `Fin`, `Archivo`) values (" .sqlvalue(@$_POST["id"], false).", " .sqlvalue(@$_POST["Clave"], true).", " .sqlvalue(@$_POST["Asignatura"], true).", " .sqlvalue(@$_POST["Escuela"], true).", " .sqlvalue(@$_POST["Nivel"], true).", " .sqlvalue(@$_POST["Inicio"], false).", " .sqlvalue(@$_POST["Fin"], false).", ".get_file_content_as_sql("Archivo").")";
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_update()
{
  global $conn;
  global $_POST;

  $sql = "update `programa` set `id`=" .sqlvalue(@$_POST["id"], false).", `Clave`=" .sqlvalue(@$_POST["Clave"], true).", `Asignatura`=" .sqlvalue(@$_POST["Asignatura"], true).", `Escuela`=" .sqlvalue(@$_POST["Escuela"], true).", `Nivel`=" .sqlvalue(@$_POST["Nivel"], true).", `Inicio`=" .sqlvalue(@$_POST["Inicio"], false).", `Fin`=" .sqlvalue(@$_POST["Fin"], false).", ".get_file_content_as_sql_for_update("Archivo") ." where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}

function sql_delete()
{
  global $conn;

  $sql = "delete from `programa` where " .primarykeycondition();
  mysql_query($sql, $conn) or die(mysql_error());
}
function bajarp($recid)
{
//connect to database
global $conn;


//query database
$sql = "SELECT Archivo FROM programa WHERE " .primarykeycondition();
$result = mysql_query($sql, $conn) or die('Error, query failed');
$content=mysql_result($result,0,"Archivo")or die(mysql_error());;

//send pdf to requesting page
header("Content-type: application/pdf");
echo $content;


}

function primarykeycondition()
{
  global $_POST;
  $pk = "";
  $pk .= "(`id`";
  if (@$_POST["xid"] == "") {
    $pk .= " IS NULL";
  }else{
  $pk .= " = " .sqlvalue(@$_POST["xid"], false);
  };
  $pk .= ")";
  return $pk;
}
function get_file_content_as_sql($fieldname)
{
  global $_FILES;
  $sql = "";
  if (!empty($_FILES))
    $sql=mysql_escape_string(file_get_contents(@$_FILES['x_'.$fieldname]['tmp_name']));
  if ($sql == '')
    $sql = 'null';
  else
   $sql = "'".$sql."'";
  return $sql;
}

function get_file_content_as_sql_for_update($fieldname)
{
  global $_POST;
  $sql = "`$fieldname` = `$fieldname`";
  if (isset($_POST["a_".$fieldname]))
  {
    switch ($_POST["a_".$fieldname]) {
    //remove
    case "2":
      $sql = "`$fieldname`= null";
      break;
    //replace
    case "3":
      $sql = "`$fieldname`=" .get_file_content_as_sql($fieldname);
      break;
    }
  }
  return $sql;
}
function outimage($recid, $field, $alt, $width, $height)
{
  $res = "<img src=\"programa.php?getimage=$recid&field=$field\" border=0 alt=\"$alt\"";
  if ($width <> '')
    $res = $res." width=\"$width\"";
  if ($height <> '')
    $res = $res." height=\"$height\"";
  $res = $res.">";
  return $res;
}

function getimage($recid, $field)
{
  $res = sql_select();
  mysql_data_seek($res, $recid);;
  $row = mysql_fetch_assoc($res);
  echo $row[$field];
}

 ?>
fin les agradesco cualquier tipo de ayuda.
PD:perdon por el multi post pero el codigo era muy largo.

Etiquetas: index, mysql, result, row, unable
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:34.