deleting multiple records from MYSQL database using PHP
Hi!
I am trying to delete at a time multiple recodes stored in MySQL database using PHP script. the problem first i track the chosen rows using checkboxes and track those records using JavaScript and passing those to a php script, first split these values and stored each of them in each array keys and using foreach statement to delete selected rows from database generating Sql statement.
but the problem is, when i split the values which javascript passing and storing each of these split values in each key of an array. The last array key remains empty and due to that the foreach statement doesn't completed as it found a black array key with no value.
can any one please advice any solution. OR how do I delete last blank array key so that others will work fine.
OR any other idea highly appreciated.
If any one wants to see the code please let me know.
the best way to accomplish this could be dynamic array of checkboxes in php and then using foreach loop for deleting more than one entry, anyhow, please show us some code.
hi im trying to insert multiple records(which consists of many rows) into database..
But, only the first row is inserted meanwhile other rows do not..
can anyone please help me..
i will provide my coding here~
//this ia add.php
PHP Code:
<HTML> <HEAD> <TITLE> Add/Remove dynamic rows in HTML table </TITLE> <SCRIPT language="javascript"> function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length; var row = table.insertRow(rowCount); var iteration = rowCount;
var cell1 = row.insertCell(0); var element1 = document.createElement("input"); element1.type = "checkbox"; cell1.appendChild(element1);
<?php $sql_tag= "SELECT * FROM cattagdesc";
$rkd = query($sql_tag); $total = sqlCount($row);
$loop = 0; ?>
var cell2 = row.insertCell(1); var element2 = document.createElement("select");
var cell3 = row.insertCell(2); var element3 = document.createElement("input"); element3.type = "text"; cell3.appendChild(element3);
var cell4 = row.insertCell(3); var element4 = document.createElement("input"); element4.type = "text"; cell4.appendChild(element4);
var cell5 = row.insertCell(4); var element5 = document.createElement("input"); element5.type = "text"; cell5.appendChild(element5);
var cell6 = row.insertCell(5); var element6 = document.createElement("input"); element6.type = "text"; cell6.appendChild(element6);
}
function deleteRow(tableID) { // grab the element again! var table = document.getElementById(tableID); // grab the length! var lastRow = table.rows.length; // delete the last row if there is more than one row! if (lastRow > 2) table.deleteRow(lastRow - 1); }
$sql1= "insert into catbiborgdesc(bib_name) values('')"; insertData($sql1,$dbName);
$sql2 = "SELECT MAX(bibID) AS max_value FROM catbiborgdesc"; $rkd = viewRecord($sql2,$dbName);
$next_bib_id = $rkd->max_value;
$sql3= "select tagID from cattagdesc WHERE tagID='".$_POST["tagID"]."'"; if($result = mysql_query($sql3,$db)) { if(mysql_num_rows($result)>0) { if ($_POST["tagID"]=='100'){ // INSERT INTO TABLE AUTHOR
$sql4 ="insert into catauthortag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,'".$_POST["tagID"]."','".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')";
insertData($sql4,$dbName);
}else if($_POST["tagID"]=='245'){ // INSERT INTO TABLE TITLE
$sql4 ="insert into cattitletag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,".$_POST["tagID"].",'".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')";
insertData($sql4,$dbName);
}else if($_POST["tagID"]=='020'){ // INSERT INTO TABLE ISBN
$sql4 ="insert into catisbntag(bibID,tagID,ind1,ind2,detail,name) values ($next_bib_id,'".$_POST["tagID"]."','".$_POST["ind1"]."','".$_POST["ind2"]."','".$_POST["detail"]."','".$_POST["name"]."')";
insertData($sql4,$dbName); } } }
?>
Last edited by Nico; 06-04-09 at 09:47 AM.
Reason: Wrappers.