Avatar of aplelois
aplelois
 asked on

delete button not working for link checker

hello,
can someone please tell me why the delete button is not working!

<?
error_reporting(E_ALL);
ini_set('display_errors', '1');

set_time_limit (0);

if($_GET) { extract($_GET, EXTR_PREFIX_SAME, "get_"); }
if($_POST) { extract($_POST, EXTR_PREFIX_SAME, "post_"); }

echo "<form action=\"checkurls.php\" method=\"post\">\n";
echo "<center></table>\n";
echo "<table width=\"600\" border=\"1\">\n";
echo "<tr><td colspan=\"3\" align=\"center\"><b>Link Exchange Cheater Checker</b></td></tr>\n";
echo "<tr><td><b>Url</b></td><td><b>Status</b></td><td style=\"text-align: center\"><b>Delete</b></td></tr>\n";
$aa=file_get_contents("config.inc.php");
preg_match_all( "/http:\/\/www.([^\"]+)\"/i" ,$aa,$ee,PREG_SET_ORDER );
$URL=$ee[0][1];

$aa=file_get_contents("links.inc.php");
preg_match_all( "/(.*?)\n/i" ,$aa,$ee,PREG_SET_ORDER );

$submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : '';
$delete = isset($_REQUEST['delete']) ? $_REQUEST['delete'] : '';

if($submit=="DeleteUrls"){
            $fp=@fopen("links.inc.php","w");
            if($fp){
                  for($i=0;$i<count($ee);$i++){
                        $x=count($ee);
                        $nn="C$x$i";
                        if($$nn!="true"){
                              if(!fwrite($fp,$ee[$i][1]."\n\n"))
                                    echo "fwrite err<br>";
                        }
                  }
                  fclose($fp);
            }else die("can't write links.inc.php");
}

$aa=file_get_contents("links.inc.php");
preg_match_all( "/(.*?)\n/i" ,$aa,$ee,PREG_SET_ORDER );

$n=0;
for($i=0;$i<count($ee);$i++){
      preg_match_all( "/href=\"([^\"]+)\"/i" ,$ee[$i][1],$ff,PREG_SET_ORDER );
      if(count($ff)==0)continue;
      $newurl=$ff[0][1];
      $bb=@file_get_contents($newurl);
      if(!$bb){
            printf("<tr><td><a href='%s'>%s</a></td><td><font color=\"green\"><b>Page Not Found</b></font></td>\n<td style=\"text-align: center\"><input type='checkbox' name=C%d%d value=\"true\" checked></td></tr>\n\n",
                  $newurl,$newurl,count($ee),$i);
      }elseif(!strstr($bb,$URL)){
            printf("<tr><td><a href='%s'>%s</a></td><td><font color=\"red\"><b>Link Not Found</b></font></td><td style=\"text-align: center\"><input type='checkbox' name=C%d%d value=true checked></td></tr>\n",$newurl,$newurl,count($ee),$i);
            $dd[$n]=$newurl;
            $n++;
      }else
            printf("<tr><td><a href='%s'>%s</a></td><td><font color=\"#4261fc\"><b>Good.. Link Found</b></font>\n</td><td style=\"text-align: center\">&nbsp;</td></tr>\n",$newurl,$newurl,count($ee),$i);
      flush();
}
if($delete=="auto"){
      $fp=@fopen("links.inc.php","w");
      if($fp){
            for($i=0;$i<count($ee);$i++){
                  if(strlen($ee[$i][1])<5)continue;
                  $f=0;
                  for($j=0;$j<$n;$j++){
                        if(strstr($ee[$i][1],$dd[$j])){
                              $f=1;
                              break;
                        }
                  }
                  if(!$f){
                        if(!fwrite($fp,$ee[$i][1]."\n\n"))
                              echo "fwrite err<br>";
                  }
            }
            fclose($fp);
      }else die("can't write links.inc.php");
}else{
      echo "<tr><td colspan=\"3\" align=\"center\"><input type=\"submit\" name=\"btnsubmit\" value=\"Delete Urls\"></td></tr>";
      echo "</table></form>";
}
?>
PHP

Avatar of undefined
Last Comment
Julian Matz

8/22/2022 - Mon
Julian Matz

Hi!

You have a space in "Delete Urls" for the value on your delete button... Should be value=\"DeleteUrls\"...
Julian Matz

Actually, if you need the space in the button value for display, then you could change:

if($submit=="DeleteUrls"){

to:

if($submit==="Delete Urls"){    // <----- add a space there also
Julian Matz

Oh, and you'll need to change this also:

$submit = isset($_REQUEST['submit']) ? $_REQUEST['submit'] : '';

to:

$submit = isset($_REQUEST['btnsubmit']) ? $_REQUEST['btnsubmit'] : '';

...because the name of your submit (Delete Urls) button is "btnsubmit"
(<input type=\"submit\" name=\"btnsubmit\" value=\"Delete Urls\">)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
aplelois

ASKER
ok I deleted the space and I try to delete but is not working!
Julian Matz


Have you sorted out the "submit" / "btnsubmit" issue ?
aplelois

ASKER
ok I did what you said about the space in both places!!
I changed the line too and its deleting the record..

I get this notices

Notice: Undefined variable: C110 in /home/virtual/site4/fst/var/www/html/hardlinks/checkurls.php on line 32
Notice: Undefined variable: C111 in /home/virtual/site4/fst/var/www/html/hardlinks/checkurls.php on line 32
Notice: Undefined variable: C112 in /home/virtual/site4/fst/var/www/html/hardlinks/checkurls.php on line 32

then I check the file config.inc.php
and I see it like this

site.com

site2.com

site3.com

and before the delete was like this
site.com
site2.com
site3.com
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
aplelois

ASKER
line 32
if($$nn!="true"){
Julian Matz

Should that line not be:

if($nn!="true"){

???
aplelois

ASKER
now it doesnt delete!
but still adds the (return key)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Julian Matz

Ok, change it back to

if($$nn!="true"){

...if that deletes the records as it should... Then try changing this line:

if(!fwrite($fp,$ee[$i][1]."\n\n"))

...to:

if(!fwrite($fp,$ee[$i][1]."\n"))

(should be line 34) ...for the extra line break problem...
aplelois

ASKER
perfect it works!!

is there a way to fix those notices on this line

if($$nn!="true"){
ASKER CERTIFIED SOLUTION
Julian Matz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
aplelois

ASKER
that was it! thank you so much!
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Julian Matz

Cool! You're welcome, glad I could help!