Welcome Guest, Not a member yet? Register   Sign In
Array from view to database (HELP)
#9

[eluser]TheFuzzy0ne[/eluser]
The code only iterates through the fields that have been selected. You could change have it do the same thing, but iterate all of the text fields on the page. I assumed you only wanted to get the information that had been selected. However, I do believe that my idea was flawed. The array indexes do not correspond with one another.

If you are relying on all of the data to be supplied, you will need to implement some validation to check it's all there. It's very easy for someone to manipulate post data, and break your application.

I think you may need to rethink your HTML layout. Perhaps do something like this:
Code:
<form action="" method="post" enctype="multipart/form-data">

<input type="checkbox" name="id[]" value="1"  />
<input type="hidden" name="name[]" value="1.jpg" />
<input type="text" name="queue[]" value="" maxlength="2" size="10" style="width:50%"  />

<input type="checkbox" name="id[]" value="2"  />
<input type="hidden" name="name[]" value="Blue_hills.jpg" />
<input type="text" name="queue[]" value="" maxlength="2" size="10" style="width:50%"  />

<input type="checkbox" name="id[]" value="3"  />
<input type="hidden" name="name[]" value="Blue_hills1.jpg" />
<input type="text" name="queue[]" value="" maxlength="2" size="10" style="width:50%"  />

Name the List:
<input type="text" name="list_name" value="" size="30" />
<input type="submit" value="Creat List" />
</form>

Note the checkboxes have IDs instead. You could then iterate through the name array (which will contain all of the results, not just the ones that are checked), and you can test whether they are checked by checking the if the id array with the given index id is empty or not. The original code was only iterating through items that had been checked, but as I mentioned, it was flawed.


Messages In This Thread
Array from view to database (HELP) - by El Forum - 02-11-2009, 03:17 AM
Array from view to database (HELP) - by El Forum - 02-11-2009, 03:35 AM
Array from view to database (HELP) - by El Forum - 02-11-2009, 03:43 AM
Array from view to database (HELP) - by El Forum - 02-11-2009, 03:51 AM
Array from view to database (HELP) - by El Forum - 02-11-2009, 04:01 AM
Array from view to database (HELP) - by El Forum - 02-11-2009, 04:57 AM
Array from view to database (HELP) - by El Forum - 02-12-2009, 01:58 AM
Array from view to database (HELP) - by El Forum - 02-12-2009, 03:35 AM
Array from view to database (HELP) - by El Forum - 02-12-2009, 06:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB