LostSole Posted February 24, 2008 Share Posted February 24, 2008 Hi Guys, i have been using AJAX to great sucess but i think I have a simple error in my PHP or SQL statement, the query executes fine but the mysql_affected_rows() statement returns 0. The row definately exists in the DB and ive checked the name for consistency, any ideas as to why this wont work? Whats especially wierd is that the deleting of sub categories works fine, but not parent categories. Values are sent to the PHP (SQL file) from this Javascript Function: function deleteCategory(catName, parentOrSub) { // are you sure you want to delete category var msg = "Are you sure you want to delete?"; if ( confirm(msg) ) { var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ var ajaxDisplay = document.getElementById('ajaxResultDiv'); ajaxDisplay.innerHTML = ajaxRequest.responseText; } } var acctID = "<?= $acctID ?>"; var queryString = "?catName=" + catName + "&parentOrSub=" + parentOrSub + "&acctID=" + acctID; ajaxRequest.open("GET","AJAXdeleteCategory.php" + queryString,true); ajaxRequest.send(null); /*document.getElementById(catName).innerHTML = "";*/ // remove row or redraw table } } PHP (SQL file) called: AJAXdeleteCategory.php <?php $DBConnect = @mysql_connect("localhost", "root", ""); if (!$DBConnect){ die("<p>The database server is not available.</p>"); } //echo "<p>Successfully connected to the database server.</p>"; $DBSelect = @mysql_select_db("hh_bud_sys"); if (!$DBSelect){ die("<p>The database is not available.</p>"); } //echo "<p>Successfully opened the database.</p>"; // Retrieve data from Query String $catName = $_GET['catName']; $parentOrSub = $_GET['parentOrSub']; $acctID = $_GET['acctID']; // Escape User Input to help prevent SQL Injection $catName = mysql_real_escape_string($catName); $parentOrSub = mysql_real_escape_string($parentOrSub); $acctID = mysql_real_escape_string($acctID); // Build query if (parentOrSub == 1) { // if it is a parent category $query = "DELETE FROM parentgroup WHERE Name = '$catName' AND AcctID = '$acctID'"; } else { // if it is a sub category $query = "DELETE FROM subgroup WHERE Name = '$catName' AND AcctID = '$acctID'"; } if (mysql_query($query)) { $affected = mysql_affected_rows(); echo "affected rows: $affected <br>"; if ($affected == 1) { echo "<h5>successfully deleted $affected category!</h5>"; } else { echo "<h5>Not deleted $catName $parentOrSub</h5>"; } } ?> Any help much appretiated, and if more info is required, please feel free to ask! Quote Link to comment Share on other sites More sharing options...
Bauer418 Posted February 24, 2008 Share Posted February 24, 2008 if (parentOrSub == 1) { // if it is a parent category should read if ($parentOrSub == 1) { // if it is a parent category That statement has probably been returning false and trying to delete a subcategory instead of a parent category. Quote Link to comment Share on other sites More sharing options...
LostSole Posted February 24, 2008 Author Share Posted February 24, 2008 ahh, told you...simple!! Your a legend, thanks alot! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.