Jump to content

PHP error


gmc1103
Go to solution Solved by gmc1103,

Recommended Posts

Hi

 

Can someone help me with this

<table id="dg" class="easyui-datagrid" url="get_atividadesByUserId.php?=<?php echo $userid ?>"
            style="width:1800px;height:500px; border:1px solid #ccc;" title="Gestão das Atividades"
            toolbar="#toolbar" pagination="true" idField="id"
            rownumbers="true" fitColumns="true" resizable="true">
            <thead>
               <tr>
                  <th field="idativade" width="20">Nº</th>
                  <th field="cargo" width="200">Cargo</th>
                  <th field="atividade" width="200">Atividade</th>
                  <th field="data" width="50">Data</th>
                  <th field="hora" width="50">Hora</th>
                  <th field="local" width="100">Local</th>
                  <th field="inter" width="200">Intervenientes</th>
                  <th field="notas" width="150">Notas</th>
               </tr>
            </thead>
         </table>

and my php

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$iduser= $_GET['userid'];
include 'conn.php';
mysql_query("SET NAMES 'utf8'");
$rs = mysql_query('SELECT  `pae_atividades`.`idativade` ,  `pae_cargo`.`cargo` ,  `pae_atividades`.`atividade` ,  `pae_atividades`.`data` ,  `pae_atividades`.`hora` ,  `pae_atividades`.`local` ,  `pae_atividades`.`inter` , `pae_atividades`.`notas` ,  `utilizador`.`nome` 
FROM  `ebspma_paad_ebspma`.`pae_atividades` 
INNER JOIN  `ebspma_paad_ebspma`.`utilizador` ON (  `pae_atividades`.`idutilizador` =  `utilizador`.`idutilizador` ) 
INNER JOIN  `ebspma_paad_ebspma`.`pae_cargo` ON (  `pae_atividades`.`idcargo` =  `pae_cargo`.`idcargo` ) 
WHERE  `pae_atividades`.`data` >= CURDATE( ) 
AND  `pae_atividades`.`idutilizador`= $iduser ORDER BY  `pae_atividades`.`data` ASC ');
$result = array();
while($row = mysql_fetch_object($rs)){
	array_push($result, $row);
}
echo json_encode($result);
?>

I'm getting this error

 

<br />
<b>Notice</b>:  Undefined index:  userid in <b>/home/ebspma/public_html/atividades/get_atividadesByUserId.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  mysql_fetch_object(): supplied argument is not a valid MySQL result resource in <b>/home/ebspma/public_html/atividades/get_atividadesByUserId.php</b> on line <b>14</b><br />
[]
 
The url passed is right
 
get_atividadesByUserId.php?=1261
 
i have the id correct
 
so whats wrong?
 
Thanks
Link to comment
Share on other sites

Thank you

 

The first error has gone but i still have the second

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$iduser= $_GET['userid'];
include 'conn.php';
mysql_query("SET NAMES 'utf8'");
$rs = mysql_query('SELECT  `pae_atividades`.`idativade` ,  `pae_cargo`.`cargo` ,  `pae_atividades`.`atividade` ,  `pae_atividades`.`data` ,  `pae_atividades`.`hora` ,  `pae_atividades`.`local` ,  `pae_atividades`.`inter` , `pae_atividades`.`notas` ,  `utilizador`.`nome` 
FROM  `ebspma_paad_ebspma`.`pae_atividades` 
INNER JOIN  `ebspma_paad_ebspma`.`utilizador` ON (  `pae_atividades`.`idutilizador` =  `utilizador`.`idutilizador` ) 
INNER JOIN  `ebspma_paad_ebspma`.`pae_cargo` ON (  `pae_atividades`.`idcargo` =  `pae_cargo`.`idcargo` ) 
WHERE  `pae_atividades`.`data` >= CURDATE( ) 
AND  `pae_atividades`.`idutilizador`= $iduser ORDER BY  `pae_atividades`.`data` ASC ');
$result = array();
while($row = mysql_fetch_object($rs)){
	array_push($result, $row);
}
echo json_encode($result);
?>

Line 14

 

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/ebspma/public_html/atividades/get_atividadesByUserId.php on line 14
[]

Link to comment
Share on other sites

Thank you

 

The first error has gone but i still have the second

<?php
error_reporting(E_ALL | E_NOTICE);
ini_set('display_errors', '1');
$iduser= $_GET['userid'];
include 'conn.php';
mysql_query("SET NAMES 'utf8'");
$rs = mysql_query('SELECT  `pae_atividades`.`idativade` ,  `pae_cargo`.`cargo` ,  `pae_atividades`.`atividade` ,  `pae_atividades`.`data` ,  `pae_atividades`.`hora` ,  `pae_atividades`.`local` ,  `pae_atividades`.`inter` , `pae_atividades`.`notas` ,  `utilizador`.`nome` 
FROM  `ebspma_paad_ebspma`.`pae_atividades` 
INNER JOIN  `ebspma_paad_ebspma`.`utilizador` ON (  `pae_atividades`.`idutilizador` =  `utilizador`.`idutilizador` ) 
INNER JOIN  `ebspma_paad_ebspma`.`pae_cargo` ON (  `pae_atividades`.`idcargo` =  `pae_cargo`.`idcargo` ) 
WHERE  `pae_atividades`.`data` >= CURDATE( ) 
AND  `pae_atividades`.`idutilizador`= $iduser ORDER BY  `pae_atividades`.`data` ASC ');
$result = array();
while($row = mysql_fetch_object($rs)){
	array_push($result, $row);
}
echo json_encode($result);
?>

Line 14

 

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/ebspma/public_html/atividades/get_atividadesByUserId.php on line 14

[]

mysql is deprecated you should use mysqli, have you tried 

while($row = mysql_fetch_object($result)){
	array_push($result, $row);
} 

Your trying to get the result from the query without actually getting the results

 

Also, 

$result = $rs->fetch();
Edited by Tom10
Link to comment
Share on other sites

mysql is deprecated you should use mysqli...

 

...or PDO. More information about the different APIs can be found here:

http://php.net/manual/en/mysqlinfo.api.choosing.php

 

 

...have you tried 

while($row = mysql_fetch_object($result)){
	array_push($result, $row);
} 

 

Based on the code originally posted, the resultset is being saved to the $rs variable.

$rs = mysql_query('SELECT  `pae_atividades`.`idativade` ... ORDER BY  `pae_atividades`.`data` ASC ');

$result contains something else.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.