Jump to content

Archived

This topic is now archived and is closed to further replies.

Anakin

Spot the Bug

Recommended Posts

Can anyone spot the bug in the code below. The script actually works! However, if I try to display the php generated xml file, I get the following;

**************************************************

<?xml version="1.0" encoding="UTF-8" ?>
- <menu>
- <menu-title label="menu">
<menu-item label="Select City ..." />
<br />
[b]<b>Warning</b>
: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in
<b>city.php</b>[/b]
on line
<b>23</b>
<br />
</menu-title>
</menu>

**************************************************

<?php

// This line connects to the database.
include_once("config.php");

//global $connection;

$country_id = $_GET[country_id];

$result = mysql_query("SELECT city_id, City FROM city WHERE country_id =".$country_id);


// And now we need to output an XML document.
// We use the names of columns as <row> properties.


echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<menu>';
echo '<menu-title label="menu">';
echo '<menu-item label="Select City ..." />';

while($row=mysql_fetch_array($result)){
$line = '<menu-item data="'.$row[city_id].'" label="'.$row[City].'"/>';
echo $line;
}
echo '</menu-title>';
echo '</menu>';

?>

Share this post


Link to post
Share on other sites
I didn't look too hard at your code, but you're looks like your 2nd " is in the wrong place in your query string.
[!--coloro:#999999--][span style=\"color:#999999\"][!--/coloro--][i]$result = mysql_query("SELECT city_id, City FROM city WHERE country_id =[b][!--coloro:#FF0000--][span style=\"color:#FF0000\"][!--/coloro--]"[!--colorc--][/span][!--/colorc--][/b].$country_id);
[/i][!--colorc--][/span][!--/colorc--]
try this instead, separate your query from your execution & make sure your query is executed:
[code]
$query = "SELECT city_id, City FROM city WHERE country_id ='$country_id'  "; //query code
$result = mysql_query($query) or die (mysql_error()."<br />Couldn't execute query: $query"); //execute!, if there is something wrong with your query, this will let you know where it is.[/code]

Share this post


Link to post
Share on other sites

×

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.