Foros del Web » Programando para Internet » PHP »

ayuda con error al modificar opciones

Estas en el tema de ayuda con error al modificar opciones en el foro de PHP en Foros del Web. les paso codigo Código HTML: <?php include("includes/security.php")?> <?php include("includes/doctype.php")?> <head> <?php include("includes/head.php")?> <?php include("includes/config.php")?> <?php include("includes/config.php")?> <?php mysql_query("SET NAMES 'utf8'"); if(isset($_POST['agregar'])) { $nuevaencuesta = mysql_query("INSERT ...
  #1 (permalink)  
Antiguo 13/09/2010, 06:48
 
Fecha de Ingreso: septiembre-2010
Mensajes: 101
Antigüedad: 13 años, 7 meses
Puntos: 0
ayuda con error al modificar opciones

les paso codigo




Código HTML:
<?php include("includes/security.php")?>
<?php include("includes/doctype.php")?>
<head>
<?php include("includes/head.php")?>
<?php include("includes/config.php")?>
<?php include("includes/config.php")?>


<?php

mysql_query("SET NAMES 'utf8'");
if(isset($_POST['agregar']))
{
	$nuevaencuesta = mysql_query("INSERT INTO  tbl_encuestasp(pregunta,fecha,status ) VALUES('".$_POST[pregunta]."',now(),'".$_POST[status]."')");
	$ultimoid=mysql_insert_id();
	$nuevaopcion=mysql_query("INSERT INTO  tbl_encuestasr(idpregunta,respuesta) VALUES('".$ultimoid."','".$_POST['opcion4']."')");
	$nuevaopcion=mysql_query("INSERT INTO  tbl_encuestasr(idpregunta,respuesta) VALUES('".$ultimoid."','".$_POST['opcion3']."')");
	$nuevaopcion=mysql_query("INSERT INTO  tbl_encuestasr(idpregunta,respuesta) VALUES('".$ultimoid."','".$_POST['opcion2']."')");
	$nuevaopcion=mysql_query("INSERT INTO  tbl_encuestasr(idpregunta,respuesta) VALUES('".$ultimoid."','".$_POST['opcion1']."')");
	$borrar =mysql_query ("DELETE FROM tbl_encuestasr WHERE respuesta = '' ");
}







if(isset($_POST['modificar'])){
	 $modificar=mysql_fetch_array(mysql_query("SELECT id,pregunta  FROM tbl_encuestasp WHERE id=".$_GET['id']));
	 $modificaropciones=mysql_query("SELECT id,idpregunta,respuesta FROM tbl_encuestasr WHERE idpregunta=".$_GET['id']);
	
	mysql_query("UPDATE tbl_encuestasp SET pregunta='".$_POST['pregunta'] ."' WHERE id=".$_POST['id']);
	//mysql_query("UPDATE tbl_encuestasr set respuesta=".$_POST['respuesta'] ." where idpregunta=".$_POST['id']);
	$num_rows = mysql_num_rows($modificaropciones);
	for($i=0;$i<$num_rows;$i++){
		//Entra cuantro veces, una por cada Opcion.
		
		$data=mysql_fetch_assoc($modificaropciones);
		// Remplaza el texto de la Opcion aunque siga igual.
		mysql_query('UPDATE tbl_encuestasr SET `respuesta` = \''.$_POST['modopcion'.($i+1)].'\' WHERE `id` = '.$data['id']);
	}
}


if(isset($_GET['b'])){
	mysql_query("DELETE FROM tbl_encuestasp where id=".$_GET['b']);	
	mysql_query("DELETE FROM tbl_encuestasr where idpregunta=".$_GET['b']);	
}


/*if(isset($_POST['Modificaropciones'])){
	mysql_query("UPDATE tbl_encuestasr SET respuesta='".$_POST['respuesta']."' WHERE idpregunta=".$_POST['id']);
	
}*/




if(isset($_GET['mstatus'])){
	if($_GET['status']==1){
		mysql_query("UPDATE tbl_encuestasp set status=0");
		mysql_query("UPDATE tbl_encuestasp set status=1 where id=".$_GET['mstatus']);
	}else{
		mysql_query("UPDATE tbl_encuestasp set status=0 where id=".$_GET['mstatus']);
	}
}



	
$miencuesta=mysql_query(("SELECT * FROM tbl_encuestasp"));





?>
<?php 

//$borrar =mysql_query ("DELETE FROM tbl_encuestasr WHERE respuesta = '' ");
/*if(isset($_POST['Modificar'])){
	mysql_query("UPDATE tbl_encuestap SET pregunta='".$_POST['opcion1']."' pregunta='".$_POST['pregunta']."' WHERE id=".$_POST['id']);	
}*/
?> 
lo demas no entra va abajo
  #2 (permalink)  
Antiguo 13/09/2010, 06:49
 
Fecha de Ingreso: septiembre-2010
Mensajes: 101
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: ayuda con error al modificar opciones

Código HTML:
Ver original
  1. <script type="text/javascript">
  2. <!--
  3. function MM_validateForm() { //v4.0
  4.  if (document.getElementById){
  5.    var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  6.    for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]);
  7.      if (val) { nm=val.name; if ((val=val.value)!="") {
  8.        if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
  9.          if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
  10.        } else if (test!='R') { num = parseFloat(val);
  11.          if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
  12.          if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
  13.            min=test.substring(8,p); max=test.substring(p+1);
  14.            if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
  15.      } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  16.    } if (errors) alert('The following error(s) occurred:\n'+errors);
  17.    document.MM_returnValue = (errors == '');
  18. } }
  19. //-->
  20.  
  21.  
  22.  
  23. </head>
  24. <?php include("includes/top.php")?>
  25. <?php include("includes/menu.php")?>
  26.  
  27. <div id="separador"></div>
  28. <div id="separador"></div>
  29.  
  30.  
  31. <h1>Administración de Encuestas</h1>
  32. <table width="600" border="0" align="center">
  33. <tr>
  34.     <td>Borrar</td>
  35.     <td>Modificar</td>
  36.     <td>Pregunta</td>
  37.     <td>Fecha</td>
  38.     <td>Status</td>
  39.     <td>Ver</td>
  40.  
  41. </tr>
  42. <?php
  43. while($var = mysql_fetch_array($miencuesta)){
  44. ?>
  45. <tr>
  46.     <td colspan="6" height="1" bgcolor="#000000"> </td>  
  47.   </tr>
  48. <tr>
  49. <td><a href="#" onClick="validarborrar(<?php echo($var['id'])?>)"><img src="images/borrar.gif" width="11" height="15" border="0" /></a></td>
  50.  
  51. <td><a href="adminencuesta.php?m=1&id=<?php echo($var['id'])?>"><img src="images/editar.gif" width="14" height="18" border="0" /></a></td>
  52.  
  53.  
  54.     <td><?php echo($var['pregunta']);?></td>
  55.     <td><?php echo($var['fecha']);?></td>
  56.     <td>
  57.    
  58.    
  59.     <?php if($var['status']==0){?>
  60.         <a href="adminencuesta.php?mstatus=<?php echo($var['id'])?>&status=1"><img src="images/cerrar.gif" width="9" height="10" border="0"  /></a>
  61.    <?php }else{ ?>
  62.    
  63.    <a href="adminencuesta.php?mstatus=<?php echo ($var['id'])?>&status=0"> <img src="images/check.gif" width="12" height="14" border="0" />
  64.    <?php } ?>
  65.    </td>
  66.    
  67.  
  68.    
  69.    
  70.  <td><a href="adminencuesta.php?v=<?php echo($var['id'])?>"><img src="images/eye-icon.png" width="24" height="13" border="0" /></a></td>  
  71.    
  72. </tr>
  73.  
  74. <?php } ?>
  75. <script>
  76. function validarborrar(id){
  77.     if(confirm("¿Esta seguro que desea borrar?")){
  78.         window.location="adminencuesta.php?b="+id;
  79.     }  
  80. }
  81.  
  82.  
  83. <?php if(isset($_GET['v'])){
  84.     $mostrar=mysql_query("SELECT * FROM tbl_encuestasp where id=".$_GET['v']);
  85.      $veropciones=mysql_query("SELECT idpregunta,respuesta FROM tbl_encuestasr WHERE idpregunta=".$_GET['v']);
  86. ?>
  87.  
  88.  
  89. <div id="separador"></div>
  90. <table width="316" height="159" align="center">
  91. <?php while($dg=mysql_fetch_assoc($mostrar)){?>
  92.    
  93.     <tr>
  94.       <td width="58">Pregunta:</td>
  95.       <td width="10">&nbsp;</td>
  96.       <td width="607" height="28"><?php echo($dg['pregunta'])?></td></tr>
  97.     <?php $ver=mysql_fetch_assoc($veropciones);?>
  98.     <tr>
  99.     <tr>
  100.       <td bgcolor="#000000"></td>
  101.       <td bgcolor="#000000"></td>
  102.     <td height="1" bgcolor="#000000"></td></tr>
  103.       <tr>
  104.         <td width="58">Opcion 1:</td>
  105.         <td width="10">&nbsp;</td>
  106.       <td width="607"><?php echo($ver['respuesta']);?></td></tr>
  107.     <?php $ver=mysql_fetch_assoc($veropciones);?>
  108.     <tr>
  109.     <tr>
  110.       <td bgcolor="#000000"></td>
  111.       <td bgcolor="#000000"></td>
  112.     <td height="1" bgcolor="#000000"></td></tr>
  113.       <tr>
  114.         <td width="58">Opcion 2:</td>
  115.         <td width="10">&nbsp;</td>
  116.       <td width="607"><?php echo($ver['respuesta']);?></td></tr>
  117.     <?php $ver=mysql_fetch_assoc($veropciones);?>
  118.     <tr>
  119.     <tr>
  120.       <td bgcolor="#000000"></td>
  121.       <td bgcolor="#000000"></td>
  122.     <td height="1" bgcolor="#000000"></td></tr>
  123.       <tr>
  124.         <td width="58">Opcion 3:</td>
  125.         <td width="10">&nbsp;</td>
  126.       <td width="607"><?php echo($ver['respuesta']);?></td></tr>
  127.      <?php $ver=mysql_fetch_assoc($veropciones);?>
  128.     <tr>
  129.     <tr>
  130.       <td bgcolor="#000000"></td>
  131.       <td bgcolor="#000000"></td>
  132.     <td height="1" bgcolor="#000000"></td></tr>
  133.       <tr>
  134.         <td width="58">Opcion 4: </td>
  135.         <td width="10">&nbsp;</td>
  136.       <td width="607"><?php echo($ver['respuesta']);?></td></tr>
  137.  
  138.  
  139.  <?php  }?>
  140.  <?php  }?>
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. <div id="separador"></div>
  159. <table align="center" >
  160. <tr>
  161. <td><a href="adminencuesta.php?a=1" >Realizar nueva encuesta</a></td>
  162. </tr>
  163. <div id="separador"></div>
  164.  
  165. <?php if(isset($_GET['a'])){?>
  166.  
  167. <form  action="adminencuesta.php"method="POST"  >
  168.   <table width="268" border="0" align="center">
  169.        
  170.         <tr>
  171.         <td width="144" height="56">Escribe tu pregunta: <input  name="pregunta" type="text" id="pregunta" size="40"  maxlength="51" align="left" /><br /></td>
  172.         </tr>
  173.         <tr><td height="1" bgcolor="#000000"></td></tr>
  174.         <tr>
  175.         <td height="42">opcion 1:  <input name="opcion1" type="text" id="opcion1"size="30"    maxlength="28" />
  176.           <input type="hidden" name="hiddenField" id="hiddenField" /></td>
  177.         </tr>
  178.          <tr><td height="1" bgcolor="#000000"></td></tr>
  179.         <tr>
  180.         <td height="44">opcion 2:  <input name="opcion2" type="text" id="opcion2"size="30"  maxlength="28"/>
  181.           <input type="hidden" name="hiddenField2" id="hiddenField2" /></td>
  182.         </tr>
  183.         <tr><td height="1" bgcolor="#000000"></td></tr>
  184.         <tr>
  185.         <td height="51">opcion 3:  <input type="text"  name="opcion3" id="opcion3"size="30"   maxlength="28"/>
  186.           <input type="hidden" name="hiddenField3" id="hiddenField3" /></td>
  187.         </tr>
  188.          <tr><td height="1" bgcolor="#000000"></td></tr>
  189.         <tr>
  190.         <td height="46">opcion 4:  <input type="text" name="opcion4" id="opcion4" size="30" maxlength="28"/>
  191.           <input type="hidden" name="hiddenField4" id="hiddenField4" /></td>
  192.         </tr>
  193.         </table>
  194.   <input name="agregar" type="submit" onClick="MM_validateForm('pregunta','','R','opcion1','','R','opcion2','','R');return document.MM_returnValue" value="Crear"  />
  195.  
  196. </form>
  197.    
  198. <p>
  199.   <?php }?>
  200.    
  201. </p>
  202.  
  203.  
  204.  
  205. <?php if(isset($_GET['m'])){
  206.        $modificar=mysql_fetch_array(mysql_query("SELECT id,pregunta  FROM tbl_encuestasp WHERE id=".$_GET['id']));
  207.        $modificaropciones=mysql_query("SELECT id,idpregunta,respuesta FROM tbl_encuestasr WHERE idpregunta=".$_GET['id']);
  208.        ?>
  209.  
  210. <form id="Modificar" name="form1"  method="POST" action="adminencuesta.php">
  211. <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
  212.  
  213.  
  214. <table align="center" border="0">
  215.   <tr>
  216.     <td height="48"width="342">Modifica la pregunta:
  217.    
  218.       <input  name="pregunta" type="text" id="pregunta" value="<?php echo($modificar['pregunta']);?>"  size="40"  maxlength="51" align="left" />
  219.      
  220.       <br /></td>
  221.   </tr>
  222.    
  223.    <tr><td height="1" bgcolor="#000000"></td></tr>
  224.   <tr>
  225.     <td height="42">Modifica la opcion 1:
  226.    
  227.     <?php $data=mysql_fetch_assoc($modificaropciones);?>
  228.    
  229.     <input name="modopcion1" type="text" id="modopcion1" value="<?php echo($data['respuesta']);?>" size="30"    maxlength="28" />
  230.  
  231.  
  232.    
  233.    
  234.   </tr>
  235.    <tr><td height="1" bgcolor="#000000"></td></tr>
  236.   <tr>
  237.     <td height="42">Modifica la opcion 2:
  238.        <?php $data=mysql_fetch_assoc($modificaropciones);?>
  239.       <input name="modopcion2" type="text" id="modopcion2" value="<?php echo($data['respuesta']);?>" size="30"  maxlength="28"/></td>
  240.   </tr>
  241.    <tr><td height="1" bgcolor="#000000"></td></tr>
  242.   <tr>  
  243.     <td height="42">Modifica la opcion 3:
  244.       <?php $data=mysql_fetch_assoc($modificaropciones);?>
  245.       <input type="text" id="modopcion3"  name="modopcion3"size="30" value="<?php echo($data['respuesta']);?>"   maxlength="28"/></td>
  246.   </tr>
  247.    <tr><td height="1" bgcolor="#000000"></td></tr>
  248.   <tr>
  249.     <td height="42">Modifica la opcion 4:
  250.        
  251.        <?php $data=mysql_fetch_assoc($modificaropciones);?>
  252.       <input type="text" id="modopcion4" name="modopcion4" value="<?php echo($data['respuesta']);?>" size="30" maxlength="28"/></td>
  253.  
  254.   </tr>
  255. <input name="modificar" type="submit" id="modificar"value="modificar" onClick="MM_validateForm('pregunta','','R','opcion1','','R','opcion2','','R');return document.MM_returnValue"   />
  256. </form>
  257. <p>&nbsp;</p>
  258.  
  259. <?php }?>
  260. <?php include("includes/botton.php")?>
  261. </body>
  262. </html>
  #3 (permalink)  
Antiguo 13/09/2010, 06:50
 
Fecha de Ingreso: septiembre-2010
Mensajes: 101
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: ayuda con error al modificar opciones

el error que me tira es este
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\xampplite\htdocs\adminsedal\adminencuesta .php on line 30

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\xampplite\htdocs\adminsedal\adminencuesta .php on line 35
  #4 (permalink)  
Antiguo 13/09/2010, 07:22
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: ayuda con error al modificar opciones

segun veo ak
Cita:
#
<?php
while($var = mysql_fetch_array($miencuesta)){
?>
no tienes ninguna variable antes que se llame $miencuesta con la ejecucion de una consulta, otra cosa es depura la consultas para que te indique el error ej
Código PHP:
Ver original
  1. mysql_query(/*tu consulta*/) or die (mysql_error());
suerte
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #5 (permalink)  
Antiguo 13/09/2010, 09:11
 
Fecha de Ingreso: septiembre-2010
Mensajes: 101
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: ayuda con error al modificar opciones

ese no es el error
  #6 (permalink)  
Antiguo 13/09/2010, 09:17
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: ayuda con error al modificar opciones

pues indica la linea donde esta el error xq asi por asi es dificil saberlo xq solo indicas el error que te da pero no somos adivinos para saber cual es la pagina, otra cosa depuraste la consulta para que te diga el error de sintaxis sql xq el error que te da es xq el resource q le indicas a la linea no esta correcto depura la consulta que hagas, indicanos cual es el error y cual es la consulta que lleva a ese mysql_fetch_array para poder ayudarte mejor
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #7 (permalink)  
Antiguo 13/09/2010, 09:23
 
Fecha de Ingreso: septiembre-2010
Mensajes: 101
Antigüedad: 13 años, 7 meses
Puntos: 0
Respuesta: ayuda con error al modificar opciones

perdon, ahi hago lo que pides
  #8 (permalink)  
Antiguo 13/09/2010, 09:28
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: ayuda con error al modificar opciones

hermano en la consulta que te lleva a ese error depura la consulta para que te diga el error de sintaxis mysql un ejemplo con una de las consultas que realizas
Código PHP:
Ver original
  1. $veropciones=mysql_query("SELECT idpregunta,respuesta FROM tbl_encuestasr WHERE idpregunta=".$_GET['v']) or die (mysql_error());
asi te diria si tienes un error en esta consulta ojo no estoy diciendo q esta lo tenga pero segun el mensaje la consulta que le estas pasando al mysql_fetch_array debe de tener un error de sintaxi sql por eso te digo eso para poder ayudarte mejor colocale esto a tus consultas y nos indicas que t dic otra cosa podrias indicarnos especificamente cual es la linea del error con su consulta especifica es decir el codigo que te esta dando el error
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way

Etiquetas: modificar, opciones
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 01:01.