Jump to content

[SOLVED] Deleting Rows


phpretard

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.