Quantcast
Viewing latest article 10
Browse Latest Browse All 25

Error Deleting Multiple Images

Hi, i have a script that should delete multiple images from a database and it worked fine while it was on a single HTML page, however since i have changed it to being in functions it seems to have stopped working.

The error i'm receiving is as follows:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bluemoon/public_html/NEWCMS/admin/deleteavatar/functions_deleteavatar.php on line 215(167 for code below)

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bluemoon/public_html/NEWCMS/admin/deleteavatar/functions_deleteavatar.php on line 230(182 for code below)

I can't work out why and have tried to get round it but with no luck.

Attached is the code of the two functions. The way it works is that the HTML calls listAvatar and then the user checkboxs the images they want to delete at which point the form calls db_delete_avatar.php and then that calls deleteAvatar.

Only thing is i keep getting the above error.

Thanks Alex
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
// listAvatar code.

function listAvatar() {


$sql = "SELECT COUNT(*) FROM avatar";
$result = mysql_query($sql) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 20;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage 
	 
"; // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result1)) { // echo data $id=$list["id"]; echo ""; } echo "
#AvatarImageviewable
".$list['avatar']."Image may be NSFW.
Clik here to view.
".$list['viewable']."
"; } // end while if ($numrows > 0) { /****** build the pagination links ******/ //Set the currentpage to whatever you need it to be $_GET['currentpage']; //Rebuild the querystring foreach($_GET as $keyname => $value) { $querystring.=$keyname . "=" . $value . "&"; } //Add it to the current script name to make the new URL $newURL = $_SERVER['PHP_SELF'] . "?" . $querystring; // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show <Goto page: First"; // get previous page num $prevpage = $currentpage - 1; // show <"; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x 0) && ($x [$x]"; // if not current page... } else { // make it a link echo " $x"; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " >"; // echo forward link for lastpage echo " Last"; } // end if /****** end build pagination links ******/ } } // deleteAvatar code function deleteAvatar() { // Check if delete button active, start this if(isset($_POST['delete'])) { // Set arrays $id_list = array(); $cat_list = array(); // Add checked items to $id_list Array for($i=0;$i0) $id_sql .= ","; $id_sql .= $value; $a++; } // Get Category Names $sqla="SELECT image FROM `avatar` WHERE id IN ($id_sql)"; $resulta = mysql_query($sqla); // Add Category Names to $cat_list Array while($rslt = mysql_fetch_array($resulta)){ $cat_list[ = $rslt['image']; } // Build SQL WHERE IN $cat_sql $cat_sql = ""; $a = "0"; foreach ($cat_list as $value) { if($a>0) $cat_sql .= ","; $cat_sql .= "'".$value."'"; $a++; } // Delete the records $sqldel = "SELECT image FROM avatar WHERE image IN ($cat_sql)"; $resultdel = mysql_query($sqldel); while($rowdel = mysql_fetch_array($resultdel)){ unlink("../avatars/".$rowdel['image']); } $sql = "DELETE FROM avatar WHERE id IN ($id_sql)"; $result = mysql_query($sql); } }

Viewing latest article 10
Browse Latest Browse All 25

Trending Articles