Copy link to clipboard
Copied
I have a list box of all 50 states where a user can select more than one. I have it set at
<select size="6" name="states1[]" multiple>
I used the Dreamweaver record insertion form and that gives code similar to
$insertSQL = sprintf("INSERT INTO XXXXX (field1, states, field3) VALUES (%s, %s, %s),
GetSQLValueString($_POST['states'], "text"),
Before the code above I have
@$states= $_POST['states1'];
if( is_array($states1)){
while (list ($states, $val) = each ($states1)) {
$result=mysql_query("INSERT INTO XXXXXX (fieldname, states) VALUES ('$fieldname,'" . join(",",$_POST["states1"]) . "')")or die("Insert Error: ".mysql_error());
}
}
else{echo "not array";}
I want to include the states1 array into the string passed. Right now, it sends multiple database records. So if I chose California and Florida, I would get one database record for each, plus my other field name. The problem is I have about 20 fields. In addition to the two records in the example above, the third record inserts everything else but the states is null. So I have three records that really should be one.
I really am pretty new to PHP coding and not for sure what to do next. Thanks.
Copy link to clipboard
Copied
I got this fixed. I had initally used the insert record wizard from Dreamweaver and couldn't get the variable holding my array into the getSQLStringValues, so I deleted all of that and used a regular insert string and at the end in the values section I used join to pull in my array.
This site was the guide I used. Very informative http://www.weberdev.com/get_example-4012.html