cGamez010
New Member
- Messages
- 37
- Reaction score
- 0
- Points
- 0
This code is supposed to retrieve the records in the table as xml nodes and insert the fields as child data nodes. The ajax works on my home pc, but not on http://ferrety.pcriot.com/. i've got the database server as localhost, the full username as set up on cpanel > MySQL Databases and the correct password. it goes through with the connection. it doesn't however, return errors or return the records with ParentID 0 on refresh/reset fields. Why won't it list the records? Here is the xml generator:
Code:
<?php
$q = $_GET["q"];
if (is_numeric($q)) {
if ($q > 3 || $q < 0) {
$q = 0;
}
} else {
$q = 0;
}
$sql = "";
$tsql = "";
function getchildren($level, $parentid) {
$sql = "SELECT * FROM 1_regions WHERE bigint_ParentRegionID = ".$parentid." ORDER BY text_RegionDescription ASC;\n";
$GLOBALS["sql"] .= $sql;
$result = mysql_query($sql);
if ($result) {
while ($row = mysql_fetch_array($result)) {
echo " <region>\n";
echo " <regionid>" . $row["bigint_RegionID"] . "</regionid>\n";
echo " <regionparent>" . $row["bigint_ParentRegionID"] . "</regionparent>\n";
echo " <regionname>" . $row["text_RegionDescription"] . "</regionname>\n";
echo " <indent>" . $level . "</indent>\n";
echo " </region>\n";
getchildren($level+1, $row["bigint_RegionID"]);
}
}
}
$conn = mysql_connect("localhost", **full dbase username**,**correct password**;
if (!$conn) {
die("Could not connect: " . mysql_error());
}
mysql_select_db("f3retty0_ferrety", $conn);
switch ($q) {
case 1: // add region
$pid = $_POST["menu_parentregion"];
$desc = $_POST["text_regionname"];
$tsql = "INSERT INTO 1_regions (text_RegionDescription, bigint_ParentRegionID) VALUES (\"".$desc."\", ".$pid.");\n";
$sql .= $tsql;
$result = mysql_query($tsql);
break;
case 2: // modify region
$id = $_POST["list_regions"];
$pid = $_POST["menu_parentregion"];
$desc = $_POST["text_regionname"];
$tsql = "UPDATE 1_regions SET bigint_ParentRegionID = ".$pid.", text_RegionDescription = \"".$desc."\" WHERE bigint_RegionID = ".$id.";\n";
$sql .= $tsql;
$result = mysql_query($tsql);
break;
case 3: // remove region
$id = $_POST["list_regions"];
$tsql = "UPDATE 1_regions SET bigint_ParentRegionID = 0 WHERE bigint_ParentRegionID = ".$id.";\n";
$sql .= $tsql;
$result = mysql_query($tsql);
$tsql = "DELETE FROM 1_regions WHERE bigint_RegionID = ".$id.";\n";
$sql .= $tsql;
$result = mysql_query($tsql);
break;
default: // (re)load form
}
header("Content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
echo "<root>\n";
getchildren(0, 0);
echo " <sql>" . $sql . "</sql>\n";
echo "</root>";
mysql_close($conn);
?>
Last edited: