Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript delete record from database

    This is driving me nuts. I have a html list that is populated from php. When i click one of these items and then click the submit button i want the javascript to take `tranID` and delete that record from the database. my code is below

    javascript
    Code:
    <script language="JavaScript"><!--<br />
    function attach_file(frm) {
       if (confirm("Are you sure you want to delete '" + frm.tithlist.value + "'"))
       {
          window.location.href = 'updatTith.php?tranID=' + frm.tithlist.value;
       }
    }
    
    </script>
    php
    PHP Code:
    <?php

    if(isset($_GET['tranID']))
    {

        include 
    '../dbcon/config.php';
        include 
    '../dbcon/opendb.php';

    //get values if input fields
    $tranID $_POST['tranID']; //Name

     
    $query mysql_query("delete from records where tranID = '$tranID'") or die(mysql_error());
       
    header('Location: ' $_SERVER['HTTP_REFERER']);
       exit;

    }

    ?>

    html

    Code:
    <form id="form2" name="form2" method="post" onSubmit="attach_file(form2);">
     <?php
    			
    			echo "<select tabindex='4' name='tithlist' id='tithlist' size='20'>";
    			$res=mysql_query("select date,tranID,name,tith from records where tith <> '0' order by date asc");
    			if(mysql_num_rows($res)==0) echo "there is no data in table..";
    			else
    			for($i=0;$i<mysql_num_rows($res);$i++) {
    			$row=mysql_fetch_assoc($res);
    			echo"<option ID='tith' value='$row[tranID]'>$row[date]_____$row[tranID]_____$row[tith]_____$row[name]</option>";
    		
    			}
    			echo'</select>';
    			
    			?>
    <input type="submit" name="Submit2" value="Submit" />
    <\form>
    Last edited by xion.truth; 03-09-2009 at 12:42 AM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    You never said what your problem is.

    My guess is:
    Code:
    onSubmit="attach_file(form2);return false">
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it never actually updates the database.

    should i add return false to the end of the onsubmit?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •