phpretard Posted October 22, 2008 Share Posted October 22, 2008 I am trying to delete about 10K rows. The script works without the form. With the from I get the error: Warning: mysql_query() [function.mysql-query]: Unable to save result set in ... on line 20 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in ... on line 24 if (isset($_POST['deleterows'])){ include ("../connect.php"); $GetId=$_POST['rowsNum']; $delete=$_POST['rowsNum']; echo $GetId; $result = mysql_query("SELECT * FROM URLS WHERE id<='$GetId'"); //<<<< LINE 20 if (!result){die(mysql_error());} while($row = mysql_fetch_array($result)) //<<<< LINE 24 { mysql_query("DELETE FROM URLS WHERE id<='$delete' "); } mysql_close($con); } // END IF else{ echo" <form action='' method='post'> <font face=arial>Delete All Rows And Lower Starting With:</font><br> <input type=text name='rowsNum' size='40' autocomplete=off> <input type=submit name='deleterows' value='Delete'> </form> "; } // END ELSE I can't seem to find the problem. Any help today? Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/ Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 I don't think you can use those operators on strings, try removing the single quotes around '$GetId' Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671880 Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 I get the same error without the single quotes and using: $result = mysql_query("SELECT * FROM URLS WHERE id<='".$GetId."' "); if (!result){die(mysql_error());} while($row = mysql_fetch_array($result)) { mysql_query("DELETE FROM URLS WHERE id<='".$delete."' "); } Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671884 Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 Also, result here should be $result if (!result){die(mysql_error());} Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671886 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 You don't need any SELECT statement of loop. <?php if (isset($_POST['deleterows'])) { include ("../connect.php"); $GetId = mysql_real_escape_string($_POST['rowsNum']); if (mysql_query("DELETE FROM URLS WHERE id <= $GetId")) { echo mysql_affected_rows() . " deleted\n"; } else { echo "Query failed " . mysql_error(); } mysql_close($con); } else { echo" <form action='' method='post'> <font face=arial>Delete All Rows And Lower Starting With:</font><br> <input type=text name='rowsNum' size='40' autocomplete=off> <input type=submit name='deleterows' value='Delete'> </form> "; } ?> Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671887 Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 Not really sure why you are selecting them all before you delete them, since you use the same number in both cases, why not just delete them? $sql = "DELETE FROM URLS WHERE id<=$GetId"; echo $sql; //verify $GetId is populated $result = mysql_query ($sql) or die ("Error in $sql" .mysql_error()); *Same idea as above Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671892 Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 That code worked. Unfortionatly id deleted every ID all 1,677,523 of them Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671896 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 *Same idea as above And only 6 minutes later! Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671902 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 That code worked. Unfortionatly id deleted every ID all 1,677,523 of them It will have deleted what you asked it to. What number did you put in your form? Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671903 Share on other sites More sharing options...
feidakila Posted October 22, 2008 Share Posted October 22, 2008 ops, removing my code, didn't see the thorpe answer Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671907 Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 1715886 Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671913 Share on other sites More sharing options...
trq Posted October 22, 2008 Share Posted October 22, 2008 1715886 is higher then 1677523 , so assuming all 1,677,523 of your records had incremnting ids, indeed that query would have removed all rows. Makes perfect sense. Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671917 Share on other sites More sharing options...
phpretard Posted October 22, 2008 Author Share Posted October 22, 2008 Oh I know. My Bad Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671922 Share on other sites More sharing options...
revraz Posted October 22, 2008 Share Posted October 22, 2008 I'm a slow typer *Same idea as above And only 6 minutes later! Link to comment https://forums.phpfreaks.com/topic/129603-solved-deleting-rows/#findComment-671932 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.