Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, I had a form with 200 checkboxes (a lot I'm sure you'll agree) the values of which were the same as the names in a mysql database. I have two problems: the first is that where ever a spelling mistake occurred the particular input would be ignored because it didn't match up with the database, the second problem is that the number of records in the database has now been upped to 1000. I don't really want to have to write out 800 lines of a form.
I came up with the following php to try to get the rows from the mysql database and display them as checkboxes - a much simpler solution, I'm sure you'll agree.Code: Select all
<?php
$con = mysql_connect("localhost","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("solvents", $con);
$sql = "SELECT * FROM solvents ORDER BY Name";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)) {
$Name = $row["Name"];
echo "<form name="myform" action="process1.php" method="POST">
<input type=checkbox name=Solvents[] value=$Name>";
}
?>Code: Select all
<body>
<form name="myform" action="process1.php" method="POST">
<input type="hidden" name="check_submit" value="1" />
<br />
Choose the solvents:<br />
<input type="checkbox" name="Solvents[]" value="water" checked="checked" /> Water<br />
.
.
.
<input type="checkbox" name="Solvents[]" value="dipropylene glycol" /> Dipropylene glycol<br />
<br /><br />
<input type="submit" />
</form>
</body>
Thank you.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]