Page 1 of 1

javascript not being utelized

Posted: Mon Sep 15, 2003 9:00 pm
by m3rajk
the javascript function isn't bringing up a confirm dialogue. it's just going ahead as if it's been confirmed. i think i did something wrong but i'm not sure what. php rendeirng page:

Code: Select all

function misc(){ # misc controls
  include("/home/joshua/includes/fyd.altincs.php"); # includes file (precautionary measure)
  $un=$_COOKIE['un']; $pw=$_COOKIE['pw']; # variables to talk to the db
  $db=mysql_connect($host, $login3, $pass3) or die("cannot access mysql"); # connect to the db
  $fyd=mysql_select_db('findyourdesire', $db) or die("cannot access db"); # get the db
  $memfind=mysql_query("SELECT uid FROM users WHERE username='$un' AND password='$pw'", $db);
  if(mysql_num_rows($memfind)==0){ # problem
    echo '<h1>We cannot find you. Are you sure you <a href="join.php">Joined?</a>';
  }else{ # we found the user
    $maininf=mysql_fetch_array($memfind); $uid=$maininf['uid']; $result=''; $worked=0;
    if(isset($_POST['act'])&&($_POST['act']=='reset')){ # reset the votes on the user
      $rstat=mysql_query("UPDATE stats SET pvt='0', pvc='0' WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)>'-1'){ $worked=1; } // did stats get reset
      else{ // there was a problem
        $errno=mysql_errno($db); $error=mysql_error($db); $result="<br />stats:$errno: $error";
      } // error has been recorded
      $rvote=mysql_query("DELETE FROM votes WHERE voteeuid='$uid'", $db);
      if((mysql_affected_rows($db)>'-1')&&($worked)){ $result="Your desirability has been reset."; }
      else{ // there was a problem
        $errno=mysql_errno($db); $error=mysql_error($db); $result.="<br />votes:$errno: $error";
      } // error has been recorded
    }elseif(isset($_POST['act'])&&($_POST['act']=='delete')){ // deleting your profile
      echo "      <p>Deleting $un...\n"; $imgbase=$faup; $npib=$fuup;
      foreach($images as $key=>$value){ # for each possible picture
        echo "      <br />Checking for $value\n"; flush(); $pica=$imgbase.$key.$un.'.jpg';
        $picb=$imgbase.'old.'.$key.$un.'.jpg'; $picc=$npib.$key.$un.'.jpg';
        /* delete the pics if they exist */
        if(is_file($pica)){ unlink($pica); echo "      <br />Removing $pica\n"; }
        if(is_file($picb)){ unlink($picb); echo "      <br />Removing $picb\n"; } 
        if(is_file($picc)){ unlink($picc); echo "      <br />Removing $picc\n"; }
      }
      echo "      <br />Deleting you from table BIO"; flush();
      $dfs=mysql_query("DELETE FROM bio WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ // successful deletion
        echo "      <br />Removed $un (user # $uid) from table BIO";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
        $result.="<br />Bio:$errno: $error";
      }
      echo "      <br />Deleting you from table COMMENTS"; flush();
      $dfs=mysql_query("DELETE FROM comments WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table COMMENTS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Comments:$errno: $error";
      }
      echo "      <br />Deleting you from table FRIENDS"; flush();
      $dfs=mysql_query("DELETE FROM friends WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table FRIENDS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Friends:$errno: $error";
      }
      echo "      <br />Deleting you from table INTERESTS"; flush();
      $dfs=mysql_query("DELETE FROM interests WHERE uid='$uid", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table INTERESTS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
        $result.="<br />Interests:$errno: $error";
      }
      echo "      <br />Deleting you from table MAIL"; flush();
      $dfs=mysql_query("DELETE FROM mail WHERE to_id='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table MAIL";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Mail:$errno: $error";
      }
      echo "      <br />Deleting you from table MSGS"; flush();
      $dfs=mysql_query("DELETE FROM msgs WHERE to_id='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table MSGS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Msgs:$errno: $error";
      }
      echo "      <br />Deleting you from table PESTS"; flush();
      $dfs=mysql_query("DELETE FROM pests WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table POSTS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Posts:$errno: $error";
      }
      echo "      <br />Deleting you from table POSTS"; flush();
      $dfs=mysql_query("DELETE FROM posts WHERE author='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table POSTS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Posts:$errno: $error";
      }
      echo "      <br />Deleting you from table STATS"; flush();
      $dfs=mysql_query("DELETE FROM stats WHERE uid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table STATS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
        $result.="<br />Stats:$errno: $error";
      }
      echo "      <br />Deleting you from table THREADS"; flush();
      $dfs=mysql_query("DELETE FROM threads WHERE thread_auth='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table THREADS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Threads:$errno: $error";
      }
      echo "      <br />Deleting you from table TOPS"; flush();
      $dfs=mysql_query("DELETE FROM tops WHERE memuid='$uid'", $db);
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table TOPS";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Tops:$errno: $error";
      }
      echo "      <br />Deleting you from table VOTES"; flush();
      $dfs=mysql_query("DELETE FROM votes WHERE voteeuid='$uid'", $db); // votes on
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table VOTES";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Votes:$errno: $error";
      }
      $dfs=mysql_query("DELETE FROM votes WHERE voteruid='$uid'", $db); // votes made this time period
      if(mysql_affected_rows($db)==1){ 
        echo "      <br />Removed $un (user # $uid) from table VOTES";
      }else{ // error
        $errno=mysql_errno($db); $error=mysql_error($db);
        $result.="<br />Votes:$errno: $error";
      }
      $result.='</p>';
      if(!($delerr)){ # stats,bio,interests did not result in an error (may be expanded to more)
        echo "      <br />Deleting you from table USERS";
        $dfs=mysql_query("DELETE FROM users WHERE uid='$uid'", $db);
        if(mysql_affected_rows($db)==1){
          echo "      <br />Deletion complete.</p>\n$errs";
        }else{ // error
          $errno=mysql_errno($db); $error=mysql_error($db); $delerr=1;
          echo "<br />Users:$errno: $error</p>\n$errs";
        }
      }else{ // something is wrong
        echo "      <br />Deletion encountered errors. uid=$uid username=$un";
        echo "      </p>\n$errs"; 
      }
    }
    // make the page
    echo <<<END
      <p>$result</p>
      <h2>NOTICE: THE FOLLOWING OPTIONS <b>CANNOT</b> BE UNDONE</h2>
      <script language="javascript">
        function doubleCheck(){
          var what=document.misc.act.value;
          
          if(what=="reset"){
            confirm("Are you sure you want to reset your score?");
          }elseif(what=="delete"){
            confirm("Are you sure you want to delete your account? (This cannot be undone)");
          }else{
            return FALSE;
          }
        }
      </script>
      <form action="{$_SERVER['PHP_SELF']}" name="misc" method="POST" onSubmit="return doubleCheck();">
        <input type="hidden" name="fn" value="misc">
        $tsnw
            <tr>
              <td align="center">
                <select name="act" size="1">
                  <option value="">Choose an Option</option>
                  <option value="reset">Reset Your Score</option>
                  <option value="delete">Delete Your Profile</option>
                </select>
              </td>
            </tr>
            <tr>
              <td align="center"><input type="submit" value="Let's Do It!"></td>
            </tr>
        </table>
      </form>
END;
  }
}
source being rendered:

Code: Select all

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;FindYourDesire.com -- Control Panel Subpage for neo&lt;/title&gt;
    &lt;meta name="Author" content="Pages coded by Josh Perlmutter for Desired Creations LLC"&gt;
    &lt;meta name="Author" content="Graphics created by Alix Stolzer for Desired Creations LLC"&gt;
    &lt;meta name="Author" content="Smileys created by Amber Beausoleil for Desired Creations LLC"&gt;
    &lt;style type="text/css"&gt;
      a &#123;text-decoration:none&#125;
    &lt;/style&gt;  &lt;/head&gt;

  &lt;body bgcolor="#878787" text="#ffffff" alink="#950c0c" vlink="#3347c5" link="#000000"&gt;
    &lt;center&gt;      &lt;p&gt;Your desirability has been reset.&lt;/p&gt;
      &lt;h2&gt;NOTICE: THE FOLLOWING OPTIONS &lt;b&gt;CANNOT&lt;/b&gt; BE UNDONE&lt;/h2&gt;
      &lt;script language="javascript"&gt;
        function doubleCheck()&#123;
          var what=document.misc.act.value;
          
          if(what=="reset")&#123;
            confirm("Are you sure you want to reset your score?");
          &#125;elseif(what=="delete")&#123;
            confirm("Are you sure you want to delete your account? (This cannot be undone)");
          &#125;else&#123;
            return FALSE;
          &#125;
        &#125;
      &lt;/script&gt;
      &lt;form action="/findyourdesire/control.php" name="misc" method="POST" onSubmit="return doubleCheck();"&gt;

	&lt;input type="hidden" name="fn" value="misc"&gt;
	&lt;table frame="void" bgcolor="#878787" border="0" cellpadding="0" cellspacing="0" text="#ffffff"&gt;
	    &lt;tr&gt;
	      &lt;td align="center"&gt;
	        &lt;select name="act" size="1"&gt;
	          &lt;option value=""&gt;Choose an Option&lt;/option&gt;
	          &lt;option value="reset"&gt;Reset Your Score&lt;/option&gt;
	          &lt;option value="delete"&gt;Delete Your Profile&lt;/option&gt;

	        &lt;/select&gt;
	      &lt;/td&gt;
	    &lt;/tr&gt;
	    &lt;tr&gt;
	      &lt;td align="center"&gt;&lt;input type="submit" value="Let's Do It!"&gt;&lt;/td&gt;
	    &lt;/tr&gt;
	&lt;/table&gt;
      &lt;/form&gt;
      &lt;font size="-2"&gt;

      &lt;p&gt;Pages coded by Josh Perlmutter for Desired Creations LLC
	&lt;br /&gt;Graphics created by ? for Desired Creations LLC
	&lt;br /&gt;Smileys created by Amber Beausoleil for Desired Creations LLC
	&lt;br /&gt;All creations copyrighted by their respective Creators. Reproduction Requires Consent of the Creator and Desired Creations LLC.
      &lt;/p&gt;
    &lt;/font&gt;
    &lt;/center&gt;
  &lt;/body&gt;
&lt;/html&gt;
can anyone help me figure out what's wrong?

Posted: Mon Sep 15, 2003 9:26 pm
by scorphus
There are 2 errors in your JavaScript code. Correction:

Code: Select all

function doubleCheck()&#123;
  var what=document.misc.act.value;

  if(what=="reset")&#123;
    confirm("Are you sure you want to reset your score?");
  &#125;else if(what=="delete")&#123; // it was ifelse, there is no a statement like this in JS
    confirm("Are you sure you want to delete your account? (This cannot be undone)");
  &#125;else&#123;
    return false; // it was FALSE, JS is case sensitive and the bool values are true or false.
  &#125;
&#125;
Hope it helps!

Regards,
Scorphus.

Posted: Tue Sep 16, 2003 1:27 pm
by m3rajk
partially. it gave the confirm dialogue and ignored the no answer.

however, there is one other place i have found useful (for the most part the ehad guy there has proven to be best person to go to on sql outside of the mysql website)

i got this from there. with BOTH fixes it works right. but only with both.
Originally posted by wheaties_box
ehh... that's a lot of code to just rummage through, but I think you may just need to put a return in front of your confirms... That way the function will actually return true if the user hits OK or false if the user hits cancel.

tell us how it works out ;)