Jump to content

Spot the Bug


Anakin

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>';

?>
Link to comment
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]
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.