Rodrigo Costa
asked on
Php / MySql Error
Hi folks, I'm getting an error that I can't seem to make it how to solve it.
What I want it is for it to list all records in a certain database. It should work since I copied from another script that I use that it is currently working... So I messed it up somewhere, but I can't seem to find it...
Any help would be much appreciated.
The error :Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tvuer925/public_html /CurtaNaUE RJ/votacao .php on line 15
Cheers!
What I want it is for it to list all records in a certain database. It should work since I copied from another script that I use that it is currently working... So I messed it up somewhere, but I can't seem to find it...
Any help would be much appreciated.
The error :Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/tvuer925/public_html
Cheers!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Formulário de Inscrição Categoria Amador</title>
<?php
$msg[0] = "Conexão com o banco falhou!";
$msg[1] = "Não foi possível selecionar o banco de dados!";
$conexao = mysql_pconnect("localhost","username","password");
mysql_select_db("tvuer925_youtube",$conexao) or die($msg[1]);
$queryFestival = "SELECT * FROM tbFestivalMaior ORDER BY id DESC";
$resultadoFestival = mysql_query($queryFestival,$conexao);
$linhaFestival = mysql_fetch_array($resultadoFestival);
?>
<style type="text/css">
body,td,th {
font-family: Verdana, Geneva, sans-serif;
}
body {
background-image: url(fundoCurta.jpg);
background-repeat: repeat;
}
a:link {
color: #333;
}
a:visited {
color: #333;
}
a:hover {
color: #333;
}
a:active {
color: #333;
}
</style>
<script type="text/javascript">
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function maybeDisableButton() {
var Pall = document.getElementById("email").value;
var disableButton = false;
if (Pall == "") disableButton = true;
document.forms['newsletter'].elements['SubmitCheck'].disabled = disableButton;
}
function validate(newsletter,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[newsletter].elements[email].value;
if(reg.test(address) == false) {
alert('Endereço de Email Inválido, favor digitar um endereço válido.');
return false;
}
}
</script>
<script type="text/javascript" src="FancyboxYOUTUBE/jquery-1.2.6.min.js">
</script>
<script type="text/javascript" src="FancyboxYOUTUBE/jquery.pngFix.pack.js">
</script>
<script type="text/javascript" src="FancyboxYOUTUBE/jquery.fancybox-1.0.0.js">
</script>
<script type="text/javascript" src="FancyboxYOUTUBE/swfobject.js"></script>
<link rel="stylesheet" type="text/css" href="FancyboxYOUTUBE/fancy.css"/>
<script type="text/javascript">
$(document).ready(function() {
$("a[@rel*=fancyvideo]").fancybox({
overlayShow: true,
showCloseButton: true,
overlayOpacity: 0.9,
frameWidth:640,
frameHeight:360
});
});
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26175414-1']);
_gaq.push(['_setDomainName', 'tvuerj.com.br']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<table width="85%" border="0" align="center">
<tr>
<td> </td>
<td align="center"><strong>Votação</strong></td>
<td> </td>
</tr>
</table>
<form id="form1" name="form1" method="post" action="votar.php">
<table width="85%" border="0" align="center">
<?php
while ($linhaFestival = mysql_fetch_array($resultadoFestival)) { ?>
<tr>
<td width="21%">Titulo: <?php echo $linhaFestival['titulo'];?></td>
<td width="74%">Sinopse:</td>
<td width="5%">Vote:</td>
</tr>
<tr>
<td><a href="http://www.youtube.com/embed/<?php echo $linhaFestival['link']; ?>" rel="fancyvideo"><img src="http://i1.ytimg.com/vi/<?php echo $linhaFestival['link']; ?>/default.jpg" alt="" width="108" height="81" border="0" /></a></p></td>
<td valign="top"><?php echo $linhaFestival['sinopse'];?></td>
<td><input type="radioId" name="radioId" id="radioId" value=<?php echo $linhaFestival['id'];?> /></td>
</tr>
<tr>
<td>Autor:</td>
<td><?php echo $linhaFestival['autor'];?></td>
<td></td>
</tr>
<tr>
<td>Equipamentos:</td>
<td><?php echo $linhaFestival['equipamentos'];?></td>
<td>Teste de LINK: <?php $linhaFestival['link'];?></td>
</tr>
<?php
}
?>
</table>
<p> </p>
</form>
</body>
</html>
It's possible that executing your query is failing for some reason and mysql_query is returning FALSE instead of the query result resource id. Try the following.
$linhaFestival = array();
$resultadoFestival = mysql_query($queryFestival,$conexao);
if(FALSE === $resultadoFestival) echo mysql_error($conexao);
else $linhaFestival = mysql_fetch_array($resultadoFestival);
You should carry out an all stage error trapping to find out whats failing.
$conexao = mysql_pconnect("localhost" ,"username ","passwor d");
if (is_resource($conexao) && stristr($conexao, “mysql”))
{
mysql_select_db("tvuer925_ youtube",$ conexao) or die($msg[1]);
$queryFestival = "SELECT * FROM tbFestivalMaior ORDER BY id DESC";
$resultadoFestival = mysql_query($queryFestival ,$conexao) ;
if ($resultadoFestival===FALS E)
{
die( 'Query failed');
}
$linhaFestival = mysql_fetch_array($resulta doFestival );
}
ELSE
die('something wrong with database connection details provided');
$conexao = mysql_pconnect("localhost"
if (is_resource($conexao) && stristr($conexao, “mysql”))
{
mysql_select_db("tvuer925_
$queryFestival = "SELECT * FROM tbFestivalMaior ORDER BY id DESC";
$resultadoFestival = mysql_query($queryFestival
if ($resultadoFestival===FALS
{
die( 'Query failed');
}
$linhaFestival = mysql_fetch_array($resulta
}
ELSE
die('something wrong with database connection details provided');
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sidebar note... Even though MySQL queries are not case-sensitive in their SELECT matching, I believe that the names of tables and columns may be case-sensitive. I know that in PHP the names of variables (but not classes or functions) are case-sensitive. You might check for capitalization.
it should return true on success, if it fails then maybe you supplied wrong database name or the user you put into mysql_pconnect() does't have select privileges on the db.
try
Open in new window