...

View Full Version : Javascript delete record from database



xion.truth
03-08-2009, 11:48 PM
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

<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

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


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

A1ien51
03-09-2009, 03:46 AM
You never said what your problem is.

My guess is:

onSubmit="attach_file(form2);return false">


Eric

xion.truth
03-09-2009, 04:16 AM
it never actually updates the database.

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum