PDA

View Full Version : mysql_fetch_array(): supplied argument is not a valid MySQL result resource


launcher
01-18-2009, 10:48 AM
Here it is...
The Flash give me this.

error

<root>
<br/>
<b>Warning</b>
: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
<b>C:\wamp\www\Flash\PHP\general.php</b>
on line
<b>26</b>
<br/>
</root>


Here's my code.

ActionScript

var xml:XML;
var xmlLoader:URLLoader = new URLLoader;

xmlLoader.load(new URLRequest("http://localhost/Flash/PHP/general.php"));
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function xmlLoaded(event:Event):void
{
xml = new XML(event.target.data);
trace(xml);
}


general.php

<?php
$sadarjanie = $_GET['vic'];
$nomer = $_GET['number'];
$iden = $_GET['id'];

$content = $sadarjanie;
$number = $nomer;
$id = $iden;

if($id == 1){$prom = "grafiti";}
else if($id == 2){$prom = "blondinki";}
else if($id == 3){$prom = "bigbrother";}
else if($id == 4){$prom = "znaeteli4e";}
else if($id == 5){$prom = "razni";}
else if($id == 6){$prom = "laforizmi";}
else if($id == 7){$prom = "pc";}
else if($id == 8){$prom = "ivan4o";}
else if($id == 9){$prom = "borci";}
echo $prom;

//the XML
echo "<?xml version=\"1.0\" ?>\n";
echo "<root>\n";
include("C:\wamp\www\Flash\PHP\Includes\conn.php");
$query = mysql_query("select * from $prom");
while($array = mysql_fetch_array($query))
{
echo "<vic id=" . $array['0'] . ">" . $array['1'] . "</vic>\n";
}
echo "</root>\n";


$number = 0;
if($number > 0)
{
if($number == 1){$var = "grafiti";}
else if($number == 2){$var = "blondinki";}
else if($number == 3){$var = "bigbrother";}
else if($number == 4){$var = "znaeteli4e";}
else if($number == 5){$var = "razni";}
else if($number == 6){$var = "laforizmi";}
else if($number == 7){$var = "pc";}
else if($number == 8){$var = "ivan4o";}
else if($number == 9){$var = "borci";}

include("C:/wamp/www/Flash/PHP/Includes/conn.php");
mysql_query("SET NAMES CP1251");
$query = "INSERT INTO `vicove`.`$var` (`id` ,`vic` )VALUES (NULL , '$content')";
$row = mysql_query($query);
mysql_close($conn);
if($row){echo "Вица ви беше оспешно добавен";}
else{echo "Вица ви не беше добавен";}
}
?>



conn.php

<?php
$host = "localhost";
$user = "root";
$pass = "";
$db = "vicove";
$conn = mysql_connect($host, $user, $pass);
$select_db = mysql_select_db($db, $conn);
?>

wvxvw
01-18-2009, 11:36 AM
This is because $prom == "". For working with XMLs in PHP use DOMDocument, and use classes instead includes. Also, you need to close the connection to the database after the script finishes (for security reasons). Use switch...case construction instead of if ... else if. Don't use SET NAMES CP1251, set everything to UTF-8 encoding, including database.

launcher
01-18-2009, 02:06 PM
This is because $prom == "".

I don't know what do you meen by this.


For working with XMLs in PHP use DOMDocument.


Whay?


and use classes instead includes.


What's the difference. Except they can be used for another scripts.


Use switch...case construction instead of if ... else if.


ok now my php look's like this..



<?php
$id = 0;
$sadarjanie = $_GET['vic'];
$nomer = $_GET['number'];
$iden = $_GET['id'];

$content = $sadarjanie;
$number = $nomer;
$id = $iden;

include("C:\wamp\www\Flash\PHP\Includes\conn.php");

switch($id > 0)
{
case $id == 1:
$prom = "grafiti";
break;
case $id == 2:
$prom = "blondinki";
break;
case $id == 3:
$prom = "bigbrother";
break;
case $id == 4:
$prom = "znaeteli4e";
break;
case $id == 5:
$prom = "razni";
break;
case $id == 6:
$prom = "laforizmi";
break;
case $id == 7:
$prom = "pc";
break;
case $id == 8:
$prom = "ivan4o";
break;
case $id == 9:
$prom = "borci";
break;

default:
print "Изберете категория";
break;
}

//the XML
echo "<?xml version=\"1.0\" ?>\n";
echo "<root>\n";
$query = mysql_query("Select * from $prom");
while($array = mysql_fetch_array($query))
{
echo "<vic id='" . $array['0'] . "'>" . $array['1'] . "</vic>\n";
}
echo "</root>\n";
mysql_close($conn);

........

?>



But now it doesn't trace anything.