I am trying to setup a form to send a selection of towns to a database. The list of towns is taken from a database with a check box next to it and the submit button at the bottom. When the button is pressed i want the information to be passed to new records for each town selected. I am using dreamweaver to create the form and php mysql is the database. I am using a repeated regeion to diplay all the towns with a check box to the left. When I select the towns only the last record i selected goes into the database! can anyone please help with this as i have spent the last 7 days and nights trying to find the answer.
This is the lastest code which still wont work!!!!
<?php require_once('../Connections/gnprint.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
$insertSQL = sprintf("INSERT INTO distributor_regeions (town) VALUES (%s)",
GetSQLValueString($_POST['textfield'], "text"));
mysql_select_db($database_gnprint, $gnprint);
$Result1 = mysql_query($insertSQL, $gnprint) or die(mysql_error());
}
$colname_town_list = "-1";
if (isset($_POST['county_select'])) {
$colname_town_list = (get_magic_quotes_gpc()) ? $_POST['county_select'] : addslashes($_POST['county_select']);
}
mysql_select_db($database_gnprint, $gnprint);
$query_town_list = sprintf("SELECT * FROM county_town WHERE county = %s", GetSQLValueString($colname_town_list, "text"));
$town_list = mysql_query($query_town_list, $gnprint) or die(mysql_error());
$row_town_list = mysql_fetch_assoc($town_list);
$totalRows_town_list = mysql_num_rows($town_list);
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form id="form2" name="form2" method="post" action="<?php echo $editFormAction; ?>">
<label></label>
<label></label>
<label></label>
<table border="1">
<tr>
<?php
do { // horizontal looper version 3
?>
<td><table width="310" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20"><input type="checkbox" name="checkbox" value="checkbox" /></td>
<td width="144"><input name="textfield" type="text" id="textfield" value="<?php echo $row_town_list['town']; ?>" /></td>
<td width="76"><input type="hidden" name="MM_insert" value="form2" /></td>
</tr>
</table></td>
<?php
$row_town_list = mysql_fetch_assoc($town_list);
if (!isset($nested_town_list)) {
$nested_town_list= 1;
}
if (isset($row_town_list) && is_array($row_town_list) && $nested_town_list++ % 3==0) {
echo "</tr><tr>";
}
} while ($row_town_list); //end horizontal looper version 3
?>
</tr>
</table>
<input type="submit" name="Submit" value="Submit" />
</form>
<a href="select_county.php">Back
</a>
</body>
</html>
<?php
mysql_free_result($town_list);
?>
Thanks in advance
Roger