here is my code that doesn't check for duplicates:
Code: Select all
<?php
session_start();
if(!isset($_SESSION['adminctrl'])){
header('Location: admin.php'); die('<a href="admin.php">Login first!</a>');
}
$query = mysql_connect("*****.net", "*****", "******") or die(mysql_error());
mysql_select_db('*****', $query) or die(mysql_error());
if (isset ($_POST['customer'])) {
$customer = ($_POST['customer']);
foreach (($_POST['product_id']) as $ID){
$sql = "INSERT INTO `customers_products` (customer, product_id) VALUES ('$customer','$ID')" ;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Customer Update</title>
</head>
<html>
<body>
<form method="post" action="test.php">
<?php
$conn = "SELECT company FROM `users`";
$result = mysql_query($conn, $query);
while ($row = mysql_fetch_row($result)) {
$user[] = $row[0];
}
echo "<select name='customer'>\n";
foreach ($user as $v) {
echo "<option value='$v'>\n" . $v . "</option>\n";
}
echo "</select>\n";
echo "<br/><br/>";
echo "<div class='check_container'>";
$conn = "SELECT product_id FROM `products`";
$result = mysql_query($conn, $query);
while ($row = mysql_fetch_row($result)) {
$product[] = $row[0];
}
foreach ($product as $y) {
echo "<input class='checkbox' type='checkbox' name='product_id[]' value='$y'>\n" . $y . "</input>\n";
}
?>
</div>
<br/><br/>
<input type="submit" name="submit" value="Update" />
</form>
</body>
</html>Code: Select all
<?php
session_start();
if(!isset($_SESSION['adminctrl'])){
header('Location: admin.php'); die('<a href="admin.php">Login first!</a>');
}
$query = mysql_connect("h41mysql61.secureserver.net", "JohnPiatt", "Jp19414281") or die(mysql_error());
mysql_select_db('JohnPiatt', $query) or die(mysql_error());
if (isset ($_POST['customer'])) {
$customer = ($_POST['customer']);
foreach (($_POST['product_id']) as $ID){
$sql = sprintf("SELECT customer FROM `customers_products` WHERE customer = '$customer' AND product_id = '$ID'");
if($result = @mysql_query($sql)){
if(!@mysql_num_rows($result)){
$sql = sprintf("INSERT INTO `customers_products` (customer, product_id) VALUES ('$customer','$ID')");
}
}
}
}
?>