Image checkbox

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
well if I do conditionals as you have shown in the example for all 200 images/checkboxes then I will have to cover all possibilities which are thousands. In your example as we were dealing with 2 images/checkboxes the possibilities are 4 (only box 1 checked, only box 2 checked, both checked or neither checked). So I am hoping there is a more efficient and less strenuous way of doing it.

On the additional point of only allowing users to submit if they have checked at least one box; I already have a page that has required fields - test page - but this demands that all fields are filled in rather than any one of them so I don't know how to make at least one required field to progress as I would need for the images/checkboxes. See what you think..
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Hum okay I didn't know you had 200 of them. I'll try to come up with something, but it might not be for today as I'm pretty busy.
 

natsuki

New Member
Messages
112
Reaction score
0
Points
0
EDIT: check for the box number and a loop

PHP:
...
for ($i = 0; $i < <total of boxes>; $i++)
{
    if (isset($_POST['box'.$i]))
    {
        $box = $_POST['box'.$i];
        $box = stripslashes($box);
        $box ? $message .= '<b>Box ' . $i + 1 . ":</b>..$box.." : ;
    }
}
....
something like that, I haven't really read and understood the whole thread so I can't reply quite intuitively.

OR

have php handle arrays in an html form: using name="box[]" for each or name="box[1]" using [] will autoindex the array and will be available to php POST or GET.

PHP:
......
if (isset($_POST['box']))
{
    $box = $_POST['box'];
    for ($i = 1; $i <= count($box); $i++)
    {
        $box[$i] = stripslashes($box[$i]);
        $box[$i] ? $message .= "<...blah" : ;
    }
}
.....
But I haven't really tested this one, but I know PHP has this "array from form element" feature.
 
Last edited:

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
Thanks guys much appreciation.

I have decided that the most logical thing to do would be to input all of the info into a database. So I have set one up. I wish to insert the 'imagecheckboxes' into the created table but cannot do so using simply:

PHP:
<?php

if(record_information($_POST['imagecheckboxes'])) {
  echo 'Message saved to DB';
}
else echo 'An SQL error occurred. Do some debugging'; 

?>

with this of course at the top of the page:

PHP:
<?php 
session_start();  

//Change these
$db = '****';
$user = '****';
$password = '****';

if(!mysql_connect('localhost', $user, $password)) {
 exit(mysql_error());
}
if(!mysql_select_db($db)) exit(mysql_error());

/* If you don't see any error messages 
either the connection was successful or 
display errors is turned off */ 
?>

<?php
function record_information($imagecheckboxes) {

 //Sanitize input

 $imagecheckboxes = mysql_real_escape_string($imagecheckboxes);

 //Build SQL insert query

 $query = "INSERT INTO `ad_application2` VALUES ('$imagecheckboxes')";



 //to debug you may want to echo $query


 //Attempt to insert record. Return result

 return mysql_query($query);

} 
?>

I don't know how else to do it because 'imagecheckboxes' is the img name from the previous page. If someone knows or believes that they can help please feel free here.

_Thanks one and all.
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Well there's nothing obvious in it that tells me it shouldn't work (I'm not a pro either). What is the problem? i.e. what error message do you get? Have you tested if your variables are what they should be by echoing them?
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
I'm not even getting an error message - not sure why. There must be some sort of difficulty with the fact that "imagecheckboxes" is the img name for all of the images (if you recall).

If anyone can suggest anything it will be warmly welcomed here

_thanks
 

Salvatos

Member
Prime Account
Messages
562
Reaction score
1
Points
18
Oh wait this
$query = "INSERT INTO `ad_application2` VALUES ('$imagecheckboxes')";
should be something like
$query = "INSERT INTO `ad_application2` (column name) VALUES ('$imagecheckboxes')";
 

bunglebrown

New Member
Messages
157
Reaction score
0
Points
0
My column name is imagecheckboxes. I've already inputted other user data to a database with the method mentioned (in my previous post) so I'm not sure of the problem here.

Also I would like to ask if the checkbox carryover (if you recall) and email should be working in Internet Explorer because currently it isn't and I'm not sure if it has always been like this or how to fix it. Thanks_
 
Top