Foros del Web » Programando para Internet » PHP »

AYUDA! Fatal error: Only variables can be passed by reference

Estas en el tema de AYUDA! Fatal error: Only variables can be passed by reference en el foro de PHP en Foros del Web. Hola estoy haciendo una pagina web de ingreso de nota... los valores los tomo a través de un array, pero mi problema es ke me ...
  #1 (permalink)  
Antiguo 29/04/2010, 06:46
Avatar de khatta  
Fecha de Ingreso: abril-2010
Mensajes: 22
Antigüedad: 14 años
Puntos: 0
AYUDA! Fatal error: Only variables can be passed by reference

Hola estoy haciendo una pagina web de ingreso de nota...
los valores los tomo a través de un array, pero mi problema es ke me da el error:

Fatal error: Only variables can be passed by reference

aki va el codigo de la pagina completa..

por fa ayuda!

Código PHP:
<?php
    session_start
();
        require_once 
"class.con.php";
        
$con= new DB("localhost","root","","fach");
?>
<html>
    <head>
        <title>Ingresar Notas</title>
        <script type='text/javascript'>
        function enviar(){
            window.document.forms[0].submit();
        }
                
                function validaNota(){
                    
                }
    </script>
    </head>
    <body>
        <form method="post" name="buscar">
            Buscar Alumnos en la Asigantura<br>
            Código Asignatura:<input name = "txtCodAs">
            <input name = "btnBuscar" type = "submit" value = "Buscar Alumnos">
        </form>
        <?php
            
if(isset($_POST['txtCodAs'])){
                
$codAsignatura $_POST['txtCodAs'];
                echo
"<br>Asignatura:<input name = 'txtAsignaturaCod' value ='$codAsignatura'>";
                
                
$consulta "SELECT al.alumno_apellido_paterno AS apeP, al.alumno_apellido_materno AS apeM,
                al.alumno_nombres AS nombres, al.alumno_rut AS rut, al.alumno_dv AS dv
                FROM alumno al, alumno_en_asignatura alas
                WHERE al.alumno_rut = alas.alumno_alumno_rut
                AND alas.asignatura_asignatura_id = '$codAsignatura'
                ORDER BY apeP"
;
                
               
        
?>
        <form method="post" name = "ingresar">
            <br><table border ='1'>
            <tr>
                <td>Rut</td>
                <td>Nombre</td>
                <td>Nota</td>
                <td>Número Nota</td>
            </tr>
        <?php
         $con
->query($consulta);
                if(
$con->num_rows()>0){
                    while(
$rs=$con->fetch()){
                        
$apellidoP $rs['apeP'];
                        
$apellidoM $rs['apeM'];
                        
$nombres $rs['nombres'];
                        
$rut $rs['rut'];
                        
$dv $rs['dv'];
                        
                        echo
"<tr><td><input type = 'text' name= 'rut[]' value = '$rut - $dv' size ='15'</td>";//celda donde va el rut con su respectivo dv
                        
echo"<td><input type = 'text' name = 'nombres[]' value = '$apellidoP $apellidoM $nombres' size = '40'></td>";//celda donde va el nombre completo del alumno
                        
echo"<td><input name = 'valorNota[]' size='3' value = '0.00'></td>";//nota del alumno
                        
echo"<td><input name = 'numeroNota[]' size = '3'></td></tr>";//posicion de la nota
                    
}
                }
            }
            
        
?>
            </table>
            <input name = "btnIngresar" type = "submit" value = "Ingresar Notas">
        <?php
            
if(isset($_POST['rut'])){
                
$tamanio sizeof('rut[]');
                for(
$i=0;$i<=$tamanio;$i++){
                    
$rut array_shift('rut');
                    
$nota =array_ shift('valorNota');
                    
$numero array_shift('numeroNota');
                    
$asigCod $_POST['txtCodAs'];
                    
                    
$insertNota "INSERT INTO nota_alumno VALUES ('','$rut','$asigCod','$nota','$numero')";
                    
$con->query($insertNota);
                }
                if(
$con->affected_rows()>0){
                    echo
"<script type = 'text/javascript'>alert('Los datos han sido insertados correctamente')</script>";    
                }else{
                    echo
"<script type = 'text/javascript'>alert('Error los datos no han sido ingresados')</script>";
                    
$error $con->error();
                    echo
"$error";
                }
            }
         
        
?>
        </form>
    </body>
</html>

Última edición por khatta; 29/04/2010 a las 06:51
  #2 (permalink)  
Antiguo 29/04/2010, 07:02
Avatar de gjx2  
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: AYUDA! Fatal error: Only variables can be passed by reference

Ok creo que el problema esta en esta parte cuando usas

la funcion array_shift

esta funcion solo acepta variable como referencia la forma de usarla es

ejemplo
Código PHP:
Ver original
  1. $rut = array("miguel","carlos","juan");
  2.  
  3. $nombres = array_shift($rut);
  4.  
  5. echo $nombres;
  #3 (permalink)  
Antiguo 29/04/2010, 07:09
Avatar de khatta  
Fecha de Ingreso: abril-2010
Mensajes: 22
Antigüedad: 14 años
Puntos: 0
Respuesta: AYUDA! Fatal error: Only variables can be passed by reference

Cita:
Iniciado por gjx2 Ver Mensaje
Ok creo que el problema esta en esta parte cuando usas

la funcion array_shift

esta funcion solo acepta variable como referencia la forma de usarla es

ejemplo
Código PHP:
Ver original
  1. $rut = array("miguel","carlos","juan");
  2.  
  3. $nombres = array_shift($rut);
  4.  
  5. echo $nombres;
gracias.. pero si te fijas yo tengo declarado mi arreglo mas arriba y no lo declaro con '$' no se si eso sera el problema... el arreglo es declarado como name en un input ne la tabla html... ahora si pongo el $ al momento de declararlas me da el siguiente error

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING

si no los pongo y dejo el codigo de esta manera...

Código PHP:
 <?php
         $con
->query($consulta);
                if(
$con->num_rows()>0){
                    while(
$rs=$con->fetch()){
                        
$apellidoP $rs['apeP'];
                        
$apellidoM $rs['apeM'];
                        
$nombres $rs['nombres'];
                        
$rut $rs['rut'];
                        
$dv $rs['dv'];
                        
                        echo
"<tr><td><input type = 'text' name= 'rut[]' value = '$rut - $dv' size ='15'</td>";//celda donde va el rut con su respectivo dv
                        
echo"<td><input type = 'text' name = 'nombres[]' value = '$apellidoP $apellidoM $nombres' size = '40'></td>";//celda donde va el nombre completo del alumno
                        
echo"<td><input name = 'valorNota[]' size='3' value = '0.00'></td>";//nota del alumno
                        
echo"<td><input name = 'numeroNota[]' size = '3'></td></tr>";//posicion de la nota
                    
}
                }
            }
            
        
?>
            </table>
            <input name = "btnIngresar" type = "submit" value = "Ingresar Notas">
        <?php
            
if(isset($_POST['rut'])){
                
$tamanio sizeof('rut[]');
                for(
$i=0;$i<=$tamanio;$i++){
                    
$rut array_shift('$rut');
                    
$nota array_shift('$valorNota');
                    
$numero array_shift('$numeroNota');
                    
$asigCod $_POST['txtCodAs'];
                    
                    
$insertNota "INSERT INTO nota_alumno VALUES ('','$rut','$asigCod','$nota','$numero')";
                    
$con->query($insertNota);
                }
me sigue dando el mismo error....

Fatal error: Only variables can...
  #4 (permalink)  
Antiguo 29/04/2010, 07:34
Avatar de gjx2  
Fecha de Ingreso: agosto-2008
Ubicación: R.D
Mensajes: 1.153
Antigüedad: 15 años, 8 meses
Puntos: 139
Respuesta: AYUDA! Fatal error: Only variables can be passed by reference

Pero khatta no me has entendido


hacer esto no es VALIDO $rut = array_shift('$rut');

Tienes que intentar de esta forma $rut = array_shift($rut); sin las comillas.
  #5 (permalink)  
Antiguo 29/04/2010, 07:41
Avatar de khatta  
Fecha de Ingreso: abril-2010
Mensajes: 22
Antigüedad: 14 años
Puntos: 0
muchas gracias ya no me aparec ese error., gracias por la ayuda.. pero ahora me aparecen muchos otros!

no se ke estará mal enmi codigo...

los errores son :

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 72

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 73

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 74

Notice: Undefined index: txtCodAs in C:\wamp\www\ingresarNotas2.php on line 75

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 72

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 73

Warning: array_shift() expects parameter 1 to be array, null given in C:\wamp\www\ingresarNotas2.php on line 74

Notice: Undefined index: txtCodAs in C:\wamp\www\ingresarNotas2.php on line 75
Cannot add or update a child row: a foreign key constraint fails (`fach`.`nota_alumno`, CONSTRAINT `fk_nota_alumno_alumno1` FOREIGN KEY (`alumno_alumno_rut`) REFERENCES `alumno` (`alumno_rut`) ON DELETE NO ACTION ON UPDATE NO ACTION)

Hola bueno me sale el siguiente error...

Warning array_shift() expects parameter 1 to be array

lo que stoy intentando hacer es ingresar las notas desde una tabla html a un bd mysql...

aki va el codigo..
Agradecería cualkier tipo de ayuda gracias!

Código PHP:
<?php
    session_start
();
        require_once 
"class.con.php";
        
$con= new DB("localhost","root","","fach");
?>
<html>
    <head>
        <title>Ingresar Notas</title>
        <script type='text/javascript'>
        function enviar(){
            window.document.forms[0].submit();
        }
                
                function validaNota(){
                    
                }
    </script>
    </head>
    <body>
        <form method="post" name="buscar">
            Buscar Alumnos en la Asigantura<br>
            Código Asignatura:<input name = "txtCodAs">
            <input name = "btnBuscar" type = "submit" value = "Buscar Alumnos">
        </form>
        <form method="post" name = "ingresar">
        <?php
            
if(isset($_POST['txtCodAs'])){
                
$codAsignatura $_POST['txtCodAs'];
                echo
"<br>Asignatura:<input name = 'txtAsignaturaCod' value ='$codAsignatura'>";
                
                
$consulta "SELECT al.alumno_apellido_paterno AS apeP, al.alumno_apellido_materno AS apeM,
                al.alumno_nombres AS nombres, al.alumno_rut AS rut, al.alumno_dv AS dv
                FROM alumno al, alumno_en_asignatura alas
                WHERE al.alumno_rut = alas.alumno_alumno_rut
                AND alas.asignatura_asignatura_id = '$codAsignatura'
                ORDER BY apeP"
;
                
               
        
?>
        
            <br><table border ='1'>
            <tr>
                <td>Rut</td>
                <td>Nombre</td>
                <td>Nota</td>
                <td>Número Nota</td>
            </tr>
        <?php
         $con
->query($consulta);
                if(
$con->num_rows()>0){
                    while(
$rs=$con->fetch()){
                        
$apellidoP $rs['apeP'];
                        
$apellidoM $rs['apeM'];
                        
$nombres $rs['nombres'];
                        
$rut $rs['rut'];
                        
$dv $rs['dv'];
                        
                        echo
"<tr><td><input type = 'text' name= 'rut[]' value = '$rut' size ='15'</td>";//celda donde va el rut con su respectivo dv
                        
echo"<td><input type = 'text' name = 'nombres[]' value = '$apellidoP $apellidoM $nombres' size = '40'></td>";//celda donde va el nombre completo del alumno
                        
echo"<td><input name = 'valorNota[]' size='3' value = '0.00'></td>";//nota del alumno
                        
echo"<td><input name = 'numeroNota[]' size = '3'></td></tr>";//posicion de la nota
                    
}
                }
            }
            
        
?>
            </table>
            <input name = "btnIngresar" type = "submit" value = "Ingresar Notas">
        <?php
            
if(isset($_POST['rut'])){
                
$tamanio sizeof('rut[]');
                
$asigCod $_POST['txtAsignaturaCod'];
                for(
$i=0;$i<=$tamanio;$i++){
                    
$rut array_shift($rut);
                    
$nota array_shift($valorNota);
                    
$numero array_shift($numeroNota);
                   
                    
                    
$insertNota "INSERT INTO nota_alumno VALUES ('','$rut','$asigCod','$nota','$numero')";
                    
$con->query($insertNota);
                }
                if(
$con->affected_rows()>0){
                    echo
"<script type = 'text/javascript'>alert('Los datos han sido insertados correctamente')</script>";    
                }else{
                    echo
"<script type = 'text/javascript'>alert('Error los datos no han sido ingresados')</script>";
                    
$error $con->error();
                    echo
"$error";
                }
            }
         
        
?>
        </form>
    </body>
</html>

Última edición por GatorV; 29/04/2010 a las 09:37
  #6 (permalink)  
Antiguo 29/04/2010, 08:24
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: AYUDA!!! Warning:array_shift() expects parameter 1 to be array

Pues el error lo dice claramente, array_shift() espera un array, y tu le estas mandando otra cosa :/
  #7 (permalink)  
Antiguo 29/04/2010, 08:39
Avatar de khatta  
Fecha de Ingreso: abril-2010
Mensajes: 22
Antigüedad: 14 años
Puntos: 0
Respuesta: AYUDA!!! Warning:array_shift() expects parameter 1 to be array

Cita:
Iniciado por darkasecas Ver Mensaje
Pues el error lo dice claramente, array_shift() espera un array, y tu le estas mandando otra cosa :/
Gracias.. Me podrias ayudar a ver en el codigo ke es lo ke esta mal??
le cambie una pequeña cosa.. pero sigue saliendo el mismo error

Código PHP:
<?php
    session_start
();
        require_once 
"class.con.php";
        
$con= new DB("localhost","root","","fach");
?>
<html>
    <head>
        <title>Ingresar Notas</title>
        <script type='text/javascript'>
        function enviar(){
            window.document.forms[0].submit();
        }
                
                function validaNota(){
                    
                }
    </script>
    </head>
    <body>
        <form method="post" name="buscar">
            Buscar Alumnos en la Asigantura<br>
            Código Asignatura:<input name = "txtCodAs">
            <input name = "btnBuscar" type = "submit" value = "Buscar Alumnos">
        </form>
        <form method="post" name = "ingresar">
        <?php
            
if(isset($_POST['txtCodAs'])){
                
$codAsignatura $_POST['txtCodAs'];
                echo
"<br>Asignatura:<input name = 'txtAsignaturaCod' value ='$codAsignatura'>";
                
                
$consulta "SELECT al.alumno_apellido_paterno AS apeP, al.alumno_apellido_materno AS apeM,
                al.alumno_nombres AS nombres, al.alumno_rut AS rut, al.alumno_dv AS dv
                FROM alumno al, alumno_en_asignatura alas
                WHERE al.alumno_rut = alas.alumno_alumno_rut
                AND alas.asignatura_asignatura_id = '$codAsignatura'
                ORDER BY apeP"
;
                
               
        
?>
        
            <br><table border ='1'>
            <tr>
                <td>Rut</td>
                <td>Nombre</td>
                <td>Nota</td>
                <td>Número Nota</td>
            </tr>
        <?php
         $con
->query($consulta);
                if(
$con->num_rows()>0){
                    while(
$rs=$con->fetch()){
                        
$apellidoP $rs['apeP'];
                        
$apellidoM $rs['apeM'];
                        
$nombres $rs['nombres'];
                        
$rut $rs['rut'];
                        
$dv $rs['dv'];
                        
                        echo
"<tr><td><input type = 'text' name= 'rutAl[]' value = '$rut' size ='15'</td>";//celda donde va el rut con su respectivo dv
                        
echo"<td><input type = 'text' name = 'nombres[]' value = '$apellidoP $apellidoM $nombres' size = '40'></td>";//celda donde va el nombre completo del alumno
                        
echo"<td><input name = 'valorNota[]' size='3' value = '0.00'></td>";//nota del alumno
                        
echo"<td><input name = 'numeroNota[]' size = '3'></td></tr>";//posicion de la nota
                        
echo"dentro del 1 if";
                    }
                }
            }
            
        
?>
            </table>
            <input name = "btnIngresar" type = "submit" value = "Ingresar Notas">
                <a href="asesor.php">inicio</a>
        <?php
            
if(isset($_POST['rutAl'])){
            echo
"dentro del if ";
                
$tamanio sizeof('rut[]');
                
$asigCod $_POST['txtAsignaturaCod'];
                for(
$i=0;$i<=$tamanio;$i++){
                    
$rut array_shift($rutAl);
                    
$nota array_shift($valorNota);
                    
$numero array_shift($numeroNota);

                    
$insertNota "INSERT INTO nota_alumno VALUES ('','$rut','$asigCod','$nota','$numero')";
                    
$con->query($insertNota);
                    echo
"$insertNota";
                }
                if(
$con->affected_rows()>0){
                    echo
"<script type = 'text/javascript'>alert('Los datos han sido insertados correctamente')</script>";    
                }else{
                    echo
"<script type = 'text/javascript'>alert('Error los datos no han sido ingresados')</script>";
                    
$error $con->error();
                    echo
"$error";
                }
            }
         
        
?>
        </form>
    </body>
</html>
  #8 (permalink)  
Antiguo 29/04/2010, 09:00
Avatar de darkasecas  
Fecha de Ingreso: marzo-2005
Ubicación: SantaCata, NL, Mexico
Mensajes: 1.553
Antigüedad: 19 años, 1 mes
Puntos: 77
Respuesta: AYUDA!!! Warning:array_shift() expects parameter 1 to be array

Le estas pasando variables que no veo que esten definidas por ningun lado, si lo que quieres es usar los valores que le mandas en el formulario, debes recibirlos por $_POST['campo']
  #9 (permalink)  
Antiguo 29/04/2010, 09:02
Avatar de khatta  
Fecha de Ingreso: abril-2010
Mensajes: 22
Antigüedad: 14 años
Puntos: 0
Respuesta: AYUDA!!! Warning:array_shift() expects parameter 1 to be array

mira si tu ves en esta parte del codigo...
echo"<tr><td><input type = 'text' name= 'rutAl[]' value = '$rut' size ='15'</td>";//celda donde va el rut con su respectivo dv
echo"<td><input type = 'text' name = 'nombres[]' value = '$apellidoP $apellidoM $nombres' size = '40'></td>";//celda donde va el nombre completo del alumno
echo"<td><input name = 'valorNota[]' size='3' value = '0.00'></td>";//nota del alumno
echo"<td><input name = 'numeroNota[]' size = '3'></td></tr>";//posicion de la nota
echo"dentro del 1 if";

estan definidas pero como names de los input.. esta mal eso?
  #10 (permalink)  
Antiguo 29/04/2010, 09:37
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: AYUDA! Fatal error: Only variables can be passed by reference

Temas unidos, por favor NO dupliques temas.

Etiquetas: fatal, reference, variables
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:32.