Uncaught Error: Call to a member function fetch_object () on boolean in - What is the error?

2

Good for everyone, I have a problem with this error, I am a beginner I searched and I have not found a solution. It is an appointment form and the database is in phpMyAdmin, this form is to attend an appointment then First only the appointments whose status is Assigned are listed.:

<?php  
require "ConexionDatos.php";
$objConexion=Conectarse();
$sql="select ci.idCita, ci.cit_fecha, ci.cit_hora, p.pac_nombres,     

p.pac_apellidos, m.med_nombres, m.med_apellidos, m.med_especialidad,  

c.con_nombre, ci.cit_estado, ci.cit_observaciones
from pacientes p, medicos m, consultorios c, citas ci
where (p.id_paciente=ci.cit_paciente)and
(m.idMedico=ci.cit_medico) and
(c.idConsultorio=ci.cit_consultorio) and
(ci.cit_estado='Asignado')";

$resultado=$objConexion->query($sql);
?>
<h1 align="center">LISTADO CITAS</h1>
<table width="90%" border="1" align="center">
<tr align="center" bgcolor="#99ff66" class="texto">
<td>Fecha</td>
<td>Hora</td>
<td>Paciente</td>
<td>Medico</td>
<td>Consultorio</td>
<td>Estado</td>
<td>Obervaciones</td>
<td>Atender</td>
</tr>
<?php 
while ($citas=$resultado->fetch_object())
{
?>
<tr>
<td><?php echo $citas->cit_fecha ?></td>
<td><?php echo $citas->cit_hora ?></td>
<td><?php echo $citas->pac_nombres." ".$citas->pac_apellidos?></td>
<td><?php echo $citas->med_nombres." " .$citas->med_apellidos?></td>
<td><?php echo $citas->con_nombre ?></td>
<td><?php echo $citas->cit_estado ?></td>
<td><?php echo $citas->cit_observaciones ?></td>


<td align="center">
<a href="frmEditarCita.php?idCita= <?php echo $citas->idCita ?>" title="clic para atender la cita"> 
<img src="../img/editar.png" width="62" height="51" border="0"    align="middle" /></a></td>
</tr>
<?php
}// cerramos ciclo while
?>
</table>

This is the code that takes me to the form to edit the appointment:

<?php 
require "ConexionDatos.php";

//se hace la consulta de acuerdo al idCita que llega
$objConexion=Conectarse();
$sql="select p.pac_nombres, p.pac_apellidos, c.cit_observaciones
from pacientes p, citas c
where (p.idPaciente=c.cit_paciente) and
(c.idCita='$_REQUEST[$idCita]')";

$resultadoCitas=$objConexion->query($sql);
$cita=$resultadoCitas->fetch_object();  
?>

<form id="form1" name="form1" method="post" action="actualizarCita.php">
<table width="43%" border="0" align="center" >
<tr bgcolor="#99ff66" class="texto">
<td colspan="2" align="center">ATENDER CITA</td>
</tr>
<tr>

<td width="33%" align="right" bgcolor="#99ff66">Paciente:</td>
<td width="67%"><label for="paciente"></label>
<input name="paciente" type="text" id="paciente" readonly="readonly"                                             

size="60" value="<?php echo $cita->pac_nombres." ".$cita->pac_apellidos ?  

>"/></td>
</tr>
<tr>
<td align="right" bgcolor="#99ff66">Observacione</td>
<td><label for="observaciones"></label>
<textarea name="observaciones" id="observaciones" cols="50" rows="10"
required="required"></textarea></td>
</tr>
<tr bgcolor="#99ff66" class="texto">
<td colspan="2" align="center"><input type="submit" name="button"  

id="button" value="enviar"/></td>
</tr>
</table>
/*se inserta un campo oculto y le asigno el valor de idCita para pasarlo con el formulario. el idCita llega a este formulario*/
<input name="idCita" type="hidden" value="<?php echo $_REQUEST['idCita']? 

>"/>
</form>

The other file code to validate the appointment:

<?php 
require "ConexionDatos.php";
extract ($_REQUEST);

$objConexion=Conectarse();
$sql="update citas set       
cit_observaciones='$_REQUEST[observaciones]',cit_estado='Atendido'
where idCita='$_REQUEST[idCita]'";
$resultado=$objConexion->query($sql);

if ($resultado) {
header("location:listarCitas.php?x=1");// x=1 se actualizo correctamente
}
else{
header("location:listarCitas.php?x=2");// x=2 problemas actualizar la cita
$objConexion->close();
}
?>
    
asked by Juanzu 22.05.2016 в 19:19
source

1 answer

2

The error you receive is because there is an error in the statement and then query returns false . The value false (boolean) has no method / function called fetch_object() which is the error shown.

As you mention in the comments , the problem is that the variable $idCita is not defined. Instead of

(c.idCita='$_REQUEST[$idCita]')

You should do

(c.idCita='" . $_REQUEST['idCita'] . "')";

Because that's the name of input on your form.

  

NOTE: as indicated by aldanux in his answer . Your code can suffer SQL injection attacks, you should use prepared statements. You can read more about SQL injection in this another question from SOes .

    
answered by 22.05.2016 / 23:05
source