sum in slq statment, why don't work
Posted: Sun Feb 07, 2010 10:47 am
Guys
This code works in localhost but not in my website. Any ideas?
Here is the error:
This code works in localhost but not in my website. Any ideas?
Code: Select all
<?php
session_start();
/* conexão à base de dados vendas*/
$mysql_id = mysql_connect('localhost', 'mariolopes', 'freixo');
mysql_select_db('mariolopes',$mysql_id);
/* verifica se quem acede é um aluno*/
$query="Select * from alunos where username='$_POST[username]' and password='$_POST[password]'" ;
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
echo $num_rows;
if ($num_rows>0){
//apanhar o nome do aluno
while($row=mysql_fetch_array($result)){
$_SESSION['nome']=$row['Nome'];
$_SESSION['tipo']="aluno";
$_SESSION['username']=$row['Username'];
$aluno=$_SESSION['nome'];
}
//faz o balanço das horas até ao momento
$query="select Aluno, sum (N_horas) as total from registo_horas where Aluno='$aluno'";
$result=mysql_query($query);
while($row=mysql_fetch_array($result)){
$_SESSION['horas']=$row['total'];
}
}
?>
Code: Select all
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\inetpub\vhosts\mariolopes.com\httpdocs\estagios\lixo.php on line 25