I have a HTML/PHP form with a Selection List field where the user can select a value from the list, fill out other text fields and save the form. The next time the user visits the site and brings up the form, I want to allow the user to edit previously entered and selected data. Now I'm fine with the text fields, but with the Selection List ..... I want the previously selected and saved 'selection value' as the displayed value in the list, but allowing this to be changed and another value to be selected and this saved. The Selection List is saved in an MySQL table and I have no problem displaying the list from this table, when the user first enters the data. Tried using Implode and Explode not sure how to make it work. I have not written any working code as I do not know where to start, but the following example shows what I am after:
1st time the user uses the form.....
Option A
Option B--- user selects from Selection List and saves as part of form
Option C
Option D
Option E
Option A
Option B..... this option is no longer what the user wants
Option C
Option D --- user changes selection from Selection List & saves as part of form
Option E
I can insert the values into the table (code shown below). But how do I allow them to edit the information with previously selected items shown!!!!!
print "Enter name: <input type=text name=id size=20><br>\n";
print "Select Items: <select name=test[] size=5 multiple >
<option value=item1 >item1</option>
<option value=item2 >item2</option>
<option value=item3 >item3</option>
<option value=item4 >item4</option>
<option value=item5 >item5</option>
<option value=item6 >item6</option>
<option value=item7 >item7</option>
</select><br>\n";
print "<br>\n";
print "(Shif+Right Mouse) for multiple selection<br>\n";
print "<br>\n";
print "<input type=submit value=Submit><input type=reset>\n";
id=$_POST['id'];
$test=$_POST['test'];
$db="select";
$link = mysql_connect("localhost","root","");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
}
//sql = "INSERT INTO table_name VALUES ('" . join(",",$_POST["test"]) . "')";
$result=mysql_query("INSERT INTO multiple (id, test) VALUES ('$id','" . join(",",$_POST["test"]) . "')")or die("Insert Error: ".mysql_error());
mysql_close($link);
print "Record added\n";
1st time the user uses the form.....
Option A
Option B--- user selects from Selection List and saves as part of form
Option C
Option D
Option E
Option A
Option B..... this option is no longer what the user wants
Option C
Option D --- user changes selection from Selection List & saves as part of form
Option E
I can insert the values into the table (code shown below). But how do I allow them to edit the information with previously selected items shown!!!!!
print "Enter name: <input type=text name=id size=20><br>\n";
print "Select Items: <select name=test[] size=5 multiple >
<option value=item1 >item1</option>
<option value=item2 >item2</option>
<option value=item3 >item3</option>
<option value=item4 >item4</option>
<option value=item5 >item5</option>
<option value=item6 >item6</option>
<option value=item7 >item7</option>
</select><br>\n";
print "<br>\n";
print "(Shif+Right Mouse) for multiple selection<br>\n";
print "<br>\n";
print "<input type=submit value=Submit><input type=reset>\n";
id=$_POST['id'];
$test=$_POST['test'];
$db="select";
$link = mysql_connect("localhost","root","");
//$link = mysql_connect("localhost",$_POST['username'],$_POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
}
//sql = "INSERT INTO table_name VALUES ('" . join(",",$_POST["test"]) . "')";
$result=mysql_query("INSERT INTO multiple (id, test) VALUES ('$id','" . join(",",$_POST["test"]) . "')")or die("Insert Error: ".mysql_error());
mysql_close($link);
print "Record added\n";