Ok
I can't believe you are allowing users to delete products from your database!
You are implying that user one gets to read the full database .. make their selection and delete the ones they don't want.
So when user two comes along they no longer can get a full listing of products from your database.
Surely you actually want the full products list to appear for everyone and depending on their selection... the page refreshes with only their selection.
And no product is deleted from the database by errant users.
You wouldn't have any products in your database or you would have to keep on repairing the database.
What you want is the script to call all products to a stock page for instance.
Item1 | Item Name | checkbox
Item2 | Item Name | checkbox
Item3 | Item Name | checkbox
User one selects by checking the box for Item1 and Item3, then clicks the button to confirm selection and the script makes a call to the db and only shows the Items as per users selection.
Item2 is NOT deleted by user one from the database
So user two will still be able to see all products and make their selection.
No need for any product to be deleted from your database.
The scripts are working however you'll need to do your own security and research the mysql_real_escape_string and apply it to where needed.
I'm not going to do all the work for you. LOL.
index.php and index-delete.php
To display total stock with select check boxes that delete product from db. [this I am sure you don't really wanna do. however I have written the script to do exactly that.
dbcon.php db connection seperated from scripts.
<?php
$host="localhost"; // Host name
$username="rkhan19"; // Mysql username
$password="Rash799"; // Mysql password
$db_name="rkhan19"; // Database name
$tbl_name="memory"; // Table name
// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");
?>
index-delete.php
<?php
include("dbcon.php");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="delete_checked.php">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">mem_id</td>
<td align="center" bgcolor="#FFFFFF"><strong>mem_id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>brand</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>model</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>megabytes</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>quantity</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>price</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>image</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="mem_id[]" type="checkbox" id="mem_id[]" value="<? echo $rows['mem_id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['mem_id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['brand']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['model']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['megabytes']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['quantity']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['price']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['image']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
<?php
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
delete_checked.php
confirms the deletion and prints out result.
<?php
include("dbcon.php");
// Check if delete button active, start this
if(isset($_POST['delete'])) //if submit was pressed
{
$mem_id = addslashes(@$_POST['mem_id']);
for($i = 0; $i<count($_POST["mem_id"]); $i++)
{
echo $_POST["mem_id"][$i] . "<BR>";
$del_id = $_POST["mem_id"][$i];
$sql = "DELETE FROM $tbl_name WHERE mem_id='$del_id'";
$result = mysql_query($sql);
print "<center>Product ID: $del_id has been deleted.</center><br>";
}
}
mysql_close();
?>
scripts for users to select and then re-display their selection without deleting products from database.
index.php
<?php
include("dbcon.php");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="select_checked.php">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">mem_id</td>
<td align="center" bgcolor="#FFFFFF"><strong>mem_id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>brand</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>model</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>megabytes</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>quantity</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>price</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>image</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="mem_id[]" type="checkbox" id="mem_id[]" value="<? echo $rows['mem_id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['mem_id']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['brand']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['model']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['megabytes']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['quantity']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['price']; ?></td>
<td bgcolor="#FFFFFF"><?php echo $rows['image']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="submit" type="submit" id="submit" value="Select"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
select_checked
<?php
include("dbcon.php");
$mem_id="";
if(isset($_POST['submit'])) //if submit was pressed
{//1
echo("<table width='400' border='0' cellpadding='3' cellspacing='1' bgcolor='#CCCCCC'>
<tr>
<td bgcolor='#FFFFFF'> </td>
<td colspan='4' bgcolor='#FFFFFF'><strong>Select multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align='center' bgcolor='#FFFFFF'>mem_id</td>
<td align='center' bgcolor='#FFFFFF'><strong>mem_id</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>brand</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>model</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>megabytes</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>quantity</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>price</strong></td>
<td align='center' bgcolor='#FFFFFF'><strong>image</strong></td>
</tr>");
$mem_id = addslashes(@$_POST['mem_id']);
for($i = 0; $i<count($_POST['mem_id']); $i++)
{//2
//echo $_POST['mem_id'][$i] . '<BR>';
$nomemid = $_POST['mem_id'][$i];
$sql="SELECT * FROM $tbl_name where mem_id='$nomemid'";
$result=mysql_query($sql) or die("Could not select from $tbl_name");
while($rows=mysql_fetch_array($result)){ //3
echo("<tr>
<td align='center' bgcolor='#FFFFFF'><input name=\"mem_id[]\" type=\"checkbox\" id=\"mem_id[]\" value=\"$rows[mem_id]\"></td>
<td bgcolor='#FFFFFF'>$rows[mem_id]</td>
<td bgcolor='#FFFFFF'>$rows[brand]</td>
<td bgcolor='#FFFFFF'>$rows[model]</td>
<td bgcolor='#FFFFFF'>$rows[megabytes]</td>
<td bgcolor='#FFFFFF'>$rows[quantity]</td>
<td bgcolor='#FFFFFF'>$rows[price]</td>
<td bgcolor='#FFFFFF'>$rows[image]</td>
</tr>");
}//3
}//2
echo("<tr>
<td colspan='5' align='center' bgcolor='#FFFFFF'><input name='submit' type='submit' id='delete' value='Submit'></td>
</tr>");
//print("<center>Mem ID: $nomemid has been selected.</center><br>");
echo("</table>
</form>");
}//1
mysql_close();
?>
Up to you to finish the work as use at your own risk.
Hope I helped
Arty