Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Checkbox Forms, Php & Mysql


I'm about to add some checkboxes to a form, and then store the data in
a column on a MySQL database. Just wanted to know best practice, at the
moment I'm writing and thinking .. God that's ungly code ...

<input type="checkbox" name="delta" <?php if ($delta==1) { echo
"checked"; }?>> Delta<br>
<input type="checkbox" name="mastercard" <?php if ($mastercard==1) {
echo "checked"; }?>> Mastercard<br>
<input type="checkbox" name="solo" <?php if ($solo==1) { echo
"checked"; }?>> Solo<br>
<input type="checkbox" name="switch" <?php if ($switch==1) { echo
"checked"; }?>> Switch<br>
<input type="checkbox" name="visa" <?php if ($visa==1) { echo
"checked"; }?>> Visa<br>

MySQL database fields ...
delta binary(1) No 0
mastercard binary(1) No 0
solo binary(1) No 0
switch binary(1) No 0
visa binary(1) No 0

When I output the fields, I get "on" or empty, and am wondering whether I am
making a good decision to do the code this way. Now I need to figure out how
to update the database based on the forms output.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Checkbox In Mysql Fields
PHP selects and shows a list of records. Next to each record is a check
box. If user checks the box the record(s) is selected and appended to
another 2nd DB....when the user finally presses a button

Basically I hope you get my drift, pretty normal but powerful stuff...
Are there any tutorials or snips on how I'd do this?

Declaring A Checkbox In A Mysql
I have a html form that consists of drop down menus, text boxes and two checkboxs. I can get all the data to be sent to a mysql db via php. But when i try to insert the checkboxes into the db i get an error stating the following:

Could not insert data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('6','a1','b1','3','c1','1234','1234','1234@1234.com Code:

How To Remove A Row In Mysql Table With A Checkbox ?
I'm having trouble writing the code for deleting a row with a checkbox.

My page allready contains an update and a insert form, which works great, but removing rows with a checkbox.This is my php code.

<?php require_once('../../Connections/fisherintranet.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO licenties (company, license) VALUES (%s, %s)",
GetSQLValueString($HTTP_POST_VARS['company'], "text"),
GetSQLValueString($HTTP_POST_VARS['license'], "text"));

mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($insertSQL, $fisherintranet) or die(mysql_error());
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form3")) {
$updateSQL = sprintf("UPDATE licenties SET company=%s, license=%s WHERE license=%s",
GetSQLValueString($HTTP_POST_VARS['company'], "text"),
GetSQLValueString($HTTP_POST_VARS['licupdate'], "text"),
GetSQLValueString($HTTP_POST_VARS['license'], "text"));

mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($updateSQL, $fisherintranet) or die(mysql_error());

$updateGoTo = "licenties.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
if ((isset($HTTP_POST_VARS["MM_remove"])) && ($HTTP_POST_VARS["MM_remove"] == "form2")) {
$removeSQL = sprintf("Delete from licenties WHERE 'ID'==???????????");

mysql_select_db($database_fisherintranet, $fisherintranet);
$Result1 = mysql_query($removeSQL, $fisherintranet) or die(mysql_error());
$removeGoTo = "licenties.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$removeGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$removeGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $removeGoTo));
}
session_start();
if ($HTTP_SESSION_VARS["statusCheck"] != "Admin")
header("Location: menu.php");
$colname_licenties = "1";
if (isset($HTTP_SESSION_VARS['companyCheck'])) {
$colname_licenties = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']);
}
mysql_select_db($database_fisherintranet, $fisherintranet);
$query_licenties = sprintf("SELECT license FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_licenties);
$licenties = mysql_query($query_licenties, $fisherintranet) or die(mysql_error());
$row_licenties = mysql_fetch_assoc($licenties);
$totalRows_licenties = mysql_num_rows($licenties);

$colname_alles = "1";
if (isset($HTTP_SESSION_VARS['companyCheck'])) {
$colname_alles = (get_magic_quotes_gpc()) ? $HTTP_SESSION_VARS['companyCheck'] : addslashes($HTTP_SESSION_VARS['companyCheck']);
}
mysql_select_db($database_fisherintranet, $fisherintranet);
$query_alles = sprintf("SELECT * FROM licenties WHERE company = '%s' ORDER BY license ASC", $colname_alles);
$alles = mysql_query($query_alles, $fisherintranet) or die(mysql_error());
$row_alles = mysql_fetch_assoc($alles);
$totalRows_alles = mysql_num_rows($alles);
?>

This is my code of my form :

<form name="form2" method="post" action="<?php echo $editFormAction; ?>">
<table width="30%" border="1" align="center" cellpadding="0" cellspacing="0" bgcolor="#999966">
<tr>
<td colspan="2" bgcolor="#999900"><div align="center"> <font color="#FFFFFF" face="Times New Roman, Times, serif"><strong>licenses</strong></font></div></td>
</tr>
<?php do { ?>
<tr>
<td><div align="center">
<p>
<input name="<?php echo $row_alles['ID']; ?>" type="checkbox" id="<?php echo $row_alles['ID']; ?>" value="<?php echo $row_alles['ID']; ?>">
<font color="#FFFFFF"> </font></p>
</div></td>
<td><div align="center">
<p><font color="#FFFFFF"><?php echo $row_licenties['license']; ?></font></p>
</div></td>
</tr>
<?php } while ($row_licenties = mysql_fetch_assoc($licenties)); ?>
</table>
<p align="center">
<input name="MM_remove" type="hidden" id="MM_remove" value="form1">
<input type="submit" name="Submit" value="Remove selected license">
</p>
</form>

Entering Mutiple Value With Checkbox Into Mysql
My form only seems to select one value when i may have selected 1 or more values from checkbox.

I want to be able to insert none or all selected from checkbox into mysql database....

Adding Checkbox Input To Mysql Db
how to pass a value from a form with a checkbox on a html page to a mysql database. I've preloaded some data and can populate a box if the data is already present in the db. But I would like to be able to check the box or uncheck the box and pass that value to the db (being able to change the value depending on whether it's checked or not). Code:

Passing A Checkbox Variable To A MySQL Db
Im the webmaster for a boxers website, and rather frequently, the publicist sends me links to articles about the boxer that I need to post. So, I set up a form that allows me to pull the information as needed and post it.

Basically I have it set up to post the Article Title, Article URL, and Article Date, and I call that information from the db. However, on occassion, one of these links will be a press release, and the only thing that changes is that the text Press Release: is added in front of the article title.

I was thinking about creating an extra field in the table called article_pr, and referencing that on the page, and if the row is empty, it would just pull up a space, and if its marked it just pulls up whatever is in there.

However, on the form, I need to have a check box that asks if it is a press release. If so, I would need it to print this in the code Press Release:<br> Is there a way to have the check box indicate whether it will put that code in the db field?

Checkbox Values Stored In Mysql
I have a series of checkboxes and need to store their values in a MySQL
table.

I'm wondering what data type people recommend:

varchar or text, exp. "True/False", "Yes/No"
tinyint, exp. "0/1"

Maybe it depends on the usage or maybe it doesn't matter and/or is a choice
of personal preference.

Comparing PHP Array From Checkbox To MySQL Table
My problem involves updating a MySQL table using checkbox input. I'm relatively new to both PHP and MySQL so I'm looking for a little direction on the smartest way to accomplish my goal.

When a user goes to a project page, they are able to categorize their project by area. The user checks a series of checkboxes and the results are stored in an arrays called $category_ids. I'll called the project id $project_id.

What I want to do is compare the array $category_ids to entries in a MySQL table for $project_id. Then I want to add the links that aren't already in the table and delete the ones that need to be deleted. The table has these fields:

projects_cat_link (table)
----------------------
category_id ¦ project_id (fields)

Does anyone have any tips on how to do this? I've gathered that maybe there's a way to get the MySQL data into a similarly formed array and then use functions like array_diff to compare. But then I'm not sure how to use the comparison in a MySQL query to add/edit/delete the links.

Pesky Checkbox Arrays And A MySQL Song Database
I'm not one who likes to ask for help, so for the last three days my brain has been turning to mush while I try to create a DJ Request Song Wish List. Anyone who can help me out will be saving me from severe insanity. :)

My goal is to:

1. Display search results for song title, artist and genre. (accomplished)
2. Allow the user to add songs to their Wish List. This is done by displaying checkboxes with the corresponding value equal to the songID. (working on it)
3. Allow the user to update their wishlist by adding/deleting songs.

So far I have a form that retrieves the song info from a database in a repeating region. In Dreamweaver:

<input name="songID[]" type="checkbox" id="songID[]" value="<b><?php echo $row_RecordsetSearchResults['Title'];?></b> by <?php echo $row_RecordsetSearchResults['Artist'];?>">

This puts the corresponding songID number into a checkbox value, which in turn is submitted by form POST action to the following page as an array.

To process this array I have:

if(isset($_POST['songID']))
{
$songID = $_POST['songID'];

print '<p>Song IDs:</p>'
// process items
$n = count($songID);
for($i = 0; $i <= $n; $i++)
{
//See if the values are being passed from POST
echo $songID[$i];
echo '<br>'
}
$songsInsert = '*'.implode('*',$_POST['songID']).'<br>'
$insertSQL = sprintf("INSERT INTO wishlist (Username, Title) VALUES (%s, %s)",
GetSQLValueString($MM_Username, "text"),
GetSQLValueString($songsInsert, "text"));

mysql_select_db($database_ToneDeaf, $ToneDeaf);

$Result1 = mysql_query($insertSQL, $ToneDeaf) or die(mysql_error());
}

The problem is, I'm using implode. It does store the songs, but only as one long block of text. So if the user picks "New York by Frank Sinatra" and "Hot In Here by Nelly" it is stored as "*New York by Frank Sinatra*Hot In Here by Nelly*" Obviously this gives me no options to make this actually readable, let alone allow the user to remove one of those songs from their list (both would be have to be removed.)

Also, referencing only the songID number as stored in the music database doesn't seem a good option, since the song database will be changing frequently and song data may be overwritten. Not sure if there's a viable workaround there.

Originally I wanted to store Title, Artist, Genre under seperate columns so I could link them to something like "See more songs from this Artist." However the more I read about arrays and multidimensional arrays, I realize I'm not ready to go there yet. (I just started learning PHP two weeks ago.)

Sending Extracted Array Data From MySQL To Checkbox
I have a list of checkboxes set up as a form that stores the data to a database cell in a comma separated string: For example: "12,13,18,110,118,21,28,31"

Each checkbox has a name of "categories" with different values. What I'd like to do is the following:

1) Extract the data from the database
2) Separate each number it into an individual array value
3) Make the checkboxes in categories.php reflect the selected or non-selected state, based upon the results from the database (selected being the numbers in the database)

Step 1 - I know how to do.
Step 2 - I assume I need to use the explode function, no?
Step 3 - Not a clue.... Code:

Forms And MySQL
I'd like to make a form that submits the data to a database. It's to make a database of members of a community, where everyone has his "member file".

Forms To MySQL
how to get input from an html form and insert them into a MySQL database, something like a simply buy/sell ads.

Securing PHP/MySQL Forms
I am now building a website + cms, again with PHP/MySQL, however this times its a little different. The website will have a form that customers use to make bookings.

they will enter their names/contact details into this form, as well as their credit card details. however, this transaction is not processed, it is instead saved to their database temporarily. The website owner then needs to login to the cms, process their data manually, then delete the credit details.

I already have set up SSL on the webserver (which is also a static ip server and apparently more secure) so that the php form is https://
but i am wanting to know whether i should be putting other measures in place? ie PHP/MySQL security. is there anything i can do to make ensure that the details will be submitted to mysql database securely and will remain safe in the database.

Problem With HTML Forms And PHP/MySQL...
I hope its simple for you...

Say a user enters "Mark's House" (without the double quotes) into a form
field.

The form is submitted, and the data is entered into the database.

When a query is made on that record, it correctly returns "Mark's House"
(without the double quotes)

But when the data is inserted into a form field (so that the data can be
edited) only "Mark" appears in the form, everything after the ' is ignored.

What is the most elegant way to avoid this. I don't really want to have to
make users escape these characters with . Is there another way?

Forms Generated From Mysql Data
I can't figure out how to get PHP to tell me which boxes were checked and how I can use this information. PHP Code:

Help In Creating Data Entry Forms With MySQL
I was wondering if any of you experts has some example of MySQL data
entry form either using PHP or any public domain software for my photo
album. I'd like to enter some description with it.

Checkbox
I am trying to make a form with 16 different checkboxes that pass on to an email. Someone got me started with the form but I'm not sure how to incorporate it into my php file.

<INPUT name=other_needs[] type=checkbox id="other_needs[]" value=reception>Reception<TD>

<TD><INPUT name=other_needs[] type=checkbox id="other_needs[]" value=Lunch>Lunch</TD>

How do I refer to the checkboxes in my php file to include the results in the email the script sends?

Checkbox And SQL
What im stuck with at the moment is how to update the SQL database with the new information acquired from a set of check boxes.

What i´ve done so far is to create the checkboxes and got the information from a table which checkboxes is needed and pre check it if it is already enabled. i have two rows in the database 1. Module_Name (name of a module) 2. is_enabled (is the module enabled 1 or 0). Code:


Checkbox Value
if i have 10 checkbox for customer interest..  how do i save that to database?? need to create 10 fields in the database??  after save.. how to display back when customer view his data.. if i choose swimming.. next time when i view back.. how to show swimming in the checkbox being checked

Checkbox
I have a database column which either holds the value 1 or 0.

Now if there is a 1 in this column I want to produce a checkbox button that is ticked, and if a 0 then nothing ticked.  So I thought it would work like this:

<input name="dayTwo[]" type="text" id="dayTwo" value="<?php echo $databaseArray['d2']?>" size="6" />

However, it does not seem to work?

Checkbox
I am creating an email form with checkbox included.

And I need the checkbox to be ticket when I enter the form though links.

IE

List of checkbox's

checkbox 1
checkbox 2
checkbox 3
checkbox 4

say I was another page and I click on a link (call the link checkbox 1) I would like the checkbox to be ticked automatically. I know this makes no sense but I hope you get the idea.

Checkbox
i have a checkbox array of some unknown size.its a dynamic array created.
i want to know out of all checkboxes how many r selected and which are they?
and then insert the data in the table based on that. i hav written the code as follows:-

<?
$no=0;
$friendname= $_POST['friendname'];
$storecount=$_POST['storeid'];
while($no<$storecount)
{
   if($friendname[$no])
   {
      $sql = "INSERT INTO groupfriends (groupid, username) VALUES ('$stid[$no]', '$friendname[$no]')";

      $result = mysql_query($sql) or die('Query

failed. ' . mysql_error());
   }
   $no=$no+1;
}
?>

i dont think this will work.it will add all the checkoxes data to the table. i want to insert only of those which r selected.

Checkbox Values
Basically, I have 2 checkbox's which are printed out for each record within my table. On the next form, each checkbox is tested for being "checked" and the database is updated accordingly.

This is fine. My problem is that I dont want users to be able to select both check-box's at the same time. After talking to "andnaess" on an earlier post and doing some reading, I decided upon using some javascript to do what i wanted.

I have found a script which does exactly what i want, and i am now incorporating it into my original php script.

I am having problems assigning a name and value variable with an array to my checkbox's. Is this possible, or have i got the wrong idea?

Checkbox Confusion!!!!
I have page1.php that displays some articles from a database by the condition 'on'

What I want to do is have checkboxes so that the articles you check won't be displayed on the web page the next time it's brought up. Essentially turn the articles checked to the 'off' condition and leave the articles that are not checked to the 'on' condition.

When you hit the submit button I want it to go to a page2.php to run an update query to change the 'on' condition to the 'off' condition for the specific articles that were previously checked. (My Primary Key in the database is Article_Number)

I think i have page1.php correct (don't quote me on this!)

<input type='checkbox' name='Display_Article' value='off'>";

But I'm completely lost on what to do for the page2.php

if($submit) {

for ($i=0; $i<count($Display_Article); $i++) {
//echo "<li>".$Display_Article[$i]."</li>";

$sql="Update articles set Display_Article='$Display_Article[$i]' where Article_Number='$Article_Number'";
$result=mysql_query($sql) or die ("Update Query Failed");
}

Checkbox Problem?
I am having trouble with checkboxes. How do you have a checkbox that it it is not checked it will still allow the form to be submitted. I am using checkboxes now, and if all the checkboxes are not checked, then it says that each of the ones that aren't checked are undefined variables why?

Problem With Checkbox
When i click on submit then the table wont be updated. I wanted to try to update the colom aw with the desired awardsid but i also wonder what happens if i have selected 2 or more checkboxes and whats entered then in the table aw, 1 & 2 or ? PHP Code:

Retain Checkbox Value
Just a quick question regarding the way to do something rather than the
actual code :-

I have a page which has some links that go through to a HTML form and
each link will check a certain checkbox. I want the form to retain the
checked status of any checkboxes that are set to checked when the user
goes back to the previous page.

Would this be best done using sessions or is there another way I could
use? I don't mind using sessions as I have used them before. I would
like to avoid using cookies but I don't really have any strong
objections to using them, it's just that they're not 100% reliable (but
then, what is?).

CheckBox Question
i started a php site in dreamweaver and i try fill data into MySql
database.

i set up a page with a form and i can fill in all the fields.

just for one field, i like to have several checkboxes. every checkbox
has a value, and they should fill the same field with their vale when
checked. i also want to keep my text box, so i can write additional
information.

at the moment, when i click more than one checkbox, only the value of
the first checkbox appears in the database. also, if there is already
some data in this cell, it delete previous data, but i would like to
keep it. preferably it should just add to information allready in the
database.

Disable Checkbox
I have a checkbox that I set by php code to be either "checked" or "".
I want to disable the ability of the user to check or uncheck it. I
tried "readonly", but that didn't work.

Checkbox Problem !
I try to display the multiple checkbox in my form and the quantity of this are depends on how many records in my database (usually the record is more than 500). So how big space it takes to display. And to solve the spaces problem, i thing i better display with horizontal scrollbar to save the space. But i don't know to do it.

Checking A Checkbox
Is it possible to preset the values of form elements with php - so that when
the client gets the page certain boxes are checked or completed - on the
fly - based on their HTML id.

Javascript has a way of doing this - but i need the functionality of PHP
too - so if i can move the whole thing over to php it owuld be better .

javascript example -

document.forms['form1'].elements['radiobuttonno'].checked = true;

Checkbox Array
checkbox arrays do not hold their respective positions as do other field arrays that are established to store the contents of selected records. The problem is that when you "uncheck" one of the elements and then repost, that array element disappears and the whole array collapses and renumbers itself with only the remaining "checked" ones -- simply useless when dealing with records in a table where all the field array elements should be in sync.

I consider it a bug -- why does the array have to collapse? Why can't it just hold a null value and keep its position? The only fix is to never hold checkbox values in an array. Store them in individual variables numbered like an array, then do an "eval" to retrieve the contents. Here's the whole thing in action: Code:

Checkbox Not Between Date
I get a database for « News » on Internet.
Side Admin, I would like a form to know witch "News" are Online or
not.

In my database mysql I get :

Date_start
and
Date_end

Outside this date, the « News » are unvisible.

In my form I put a checkbox « Off_line »

If it's check, all the news outside Date_start
And Date_end must be visible.

I tryed like this

In Head :
<?php
if (isset($HTTP_GET_VARS["date_off"]))
{
$ date_off =$HTTP_GET_VARS["date_off"];
}
else
{
$ date_off =0;
}
?>

In my form for checkbox :
<input <?php if ("CURRENT_DATE NOT BETWEEN $row_R_news['date_start']
AND $row_R_news['date_end'] ",1) {echo "checked="checked"";} ?>
name=" date_off " type="checkbox" id=" date_off " value="1">

For my request sql :
SELECT t_news.*
FROM t_news
WHERE $date_off

Checkbox Array
I have a list of checkboxes. The name for each is being pulled up from a database. Each (minus irrelevent or implicit code) looks like this ...

<input type=checkbox name=assnid$assnarray[assnid] value=1>

or...peaking at the HTML, the list looks like this:

<input type=checkbox name=assnid1 value=1>
<input type=checkbox name=assnid2 value=1>
<input type=checkbox name=assnid3 value=1>

and so on...
Anybody know how to post the selected checkboxes into $assnidarray?
For example, assuming all are chosen, $assnidarray would be (1,2,3,...).

Checkbox Array
I have a checkbox array containing the id of a record in a MySQL database.
The checkboxes are created dynamically depending on what is stored in the
database. I want to send the checkbox array to my stop_subscriptions.php
file, running the code on all checked boxes, however I dont seem to be able
to actually send the array, I was hoping that someone could steer me in the
right direction.

<?php
$sql = "SELECT i.type, i.title , s.inj_id FROM inj_subscription s,
injustices i WHERE s.member_id = '$user' AND i.inj_id = s.inj_id AND
s.inj_id IS NOT null" ;
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result) ;
if ($row) {
echo "<div><span>Specific Subsriptions:</span><br/>" ;
$table_start ='<table width="90%" table name="table2" align="center"
cellspacing="0" border="0">
<tr>
<form method="post" action="stop_subscription.php">
<th width="20%">Type</th>
<th width="70%">Title</th>
<th width="10%"></th>
<input type="submit" name="Submit" value="Submit"
style="font-size:10px"/><p>
<input type="hidden" name="stop_subscription"
value="1"/>
</form>
</tr>'
echo $table_start;
$rownum = 0;
while($row) {
$rownum++;
$style = rowcolor($rownum);
$table_rows .= '<td id="td" align="center"
style="'.$style.'padding:5px;" >'."
".'<form><input type="checkbox"
name="deletethis[]" value="'.$row['inj_id'] . '"></form></td>'."
";
echo "<tr>" . $table_rows . "</tr>";
$row = mysql_fetch_assoc($result) ;
}
echo '</table><Br/></div><br/>'
}
?>

Checkbox Is Checked
how do u say that if the checkbox is checked, than do something.

Checkbox Without Array
I have a question regarding implementing a checkbox that DOESN'T use arrays -- everything i find when i google has arrays in it!  So, I'm hoping someone here can help me come up with a solution to my problem.

I have a checkbox that a user can check (default will be to have it NOT checked) - and once it's checked, to keep it checked until the user unselects it again.

Here's my checkbox code:
<input type ="submit" name="cv_permission" type="checkbox">

What do I have to do to keep it turned 'ON' once it's checked?

Checkbox FormMailer
Ive got this problem and i have no idea how to fix it. Ive been trying to do it in PERL, but thats not my strong point, and i know a lot more PHP than perl. But still dont know enough to try and achive what i want to do.

Basically i am trying to have a web form in which the company fills out the form and can select which people to send the form to. Code:

$_POST Checkbox
I'm trying to create a validate members page that lists all the unvalidated members and beside it is a checkbox with the name attribute being the member's name. Is there a way to create a foreach loop to check all the $_POST and check if it's empty, and if not, do something?

For Each None Checked Checkbox
I need help with foreach none checked checkbox as value, can you even do that. I tryed the !isset(); function but i'm not sure it would work because the none checked box would not of run with the $_POST ( i think ) this is an example table of what i'm looking for help with:

({num}) = the value
[] = the checkbox.

(1)(2)(3)(4)
 [] []  [] []

the person checks the one(s) they wish to keep and the none checked ones get swaped for diffrant values. I'm not quite sure if it is possible, but i will ask anyway to see if anyone as a solution.

Checkbox Blues
I have the following checkboxes where I am using an array called check[] ...

<input name = "check[]" type = "checkbox" value = 'somevalue1' />
<input name = "check[]" type = "checkbox" value = 'somevalue2' />
<input name = "check[]" type = "checkbox" value = 'somevalue3' />

When selected by the user, I wish to delete the selected records using this code ...

// capture checkbox data
$data = $_POST['check'];

// start delete loop
foreach ($data as $key => $value )
   {
    // create SQL string
    $SQL = 'DELETE FROM ' . $table . ' WHERE name = "' . $value .'"';
   
    // run SQL query
    code goes here
   }

This code works fine ! BUt the javascipt functionality that references it does not work ! What I would like to know is how I can do the same thing but AVOID using the check[] array, by using checkboxes like this ...

<input name = "check" type = "checkbox" value = 'somevalue1' />
<input name = "check" type = "checkbox" value = 'somevalue2' />
<input name = "check" type = "checkbox" value = 'somevalue3' />

Has anyone got any good references for dealing with checkboxes in php ?

Checkbox Data In The Database
I want to display the checkboxes taken from the database from table “const_skills”, but the checkboxes and its values do not appear ($html_skills). Can anyone figure this out. Below is the codes that I’ve been using.
Thanks in advance.

<?php
include "dbinfo.php3";

function get_checkbox_labels($table_name) {
/* make an array */
$arr = array();

/* construct the query */
$query = "SELECT * FROM $table_name";

/* execute the query */
$qid = mysql_query($query);

/* each row in the result set will be packaged as
an object and put in an array */
while($row= mysql_fetch_object($qid)) {
$array[count($arr)] = $row;
}
return $arr;
}

/* Prints a nicely formatted table of checkbox choices.
$arr is an array of objects that contain the choices
$num is the number of elements wide we display in the table
$width is the value of the width parameter to the table tag
$name is the name of the checkbox array
$checked is an array of element names that should be checked
*/

function make_checkbox_html($arr, $num, $width, $name, $checked) {

/* create string to hold out html */
$str = "";

/* make it */
$str .= "<table width="$width" border="0">n";
$str .= "<tr>n";

/* determine if we will have to close add
a closing tr tag at the end of our table */
if (count($arr) % $num != 0) {
$closingTR = true;
}

$i = 1;
if (isset($checked)) {
/* if we passed in an array of the checkboxes we want
to be displayed as checked */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id"";

reset($checked);
while (list(, $entry)=each($checked)) {

if ($entry == $ele->id) {
$str .= "checked";
continue;
}
}
$str .= ">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}

} else {
/* we just want to print the checkboxes. none will have checks */
reset($arr);
while (list(, $ele)=each($arr)) {
$str .= "<td><input type="checkbox" name="$name" value="$ele->id">";
$str .= "$ele->value";

if ($i % $num == 0) {
$str .= "</tr>n<tr>";
} else {
$str .= "</td>n";
}
$i++;
}
}
/* tack on a closing tr tag if necessary */
if ($closingTR == true) {
$str .= "</tr></table>n";
} else {
$str .= "</table>n";
}
return $str;
}
/* get the checkbox labels */
$skills = get_checkbox_labels("const_skills");

/* create the html code for a formatted set of
checkboxes */
$html_skills = make_checkbox_html($skills, 3, 400, "skills[]",$checked);
?>

<html>
<body bgcolor="#ffffff" text="#000000" id=all>
<br>
<form name="skills" method="POST" action="insertskills.php3">
Check off your web development skills:
<? echo "$html_skills"; ?>
<br>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Record Unchecked Checkbox
Is there a way to record a checkbox that is not checked?

Checking For Checkbox Array
I'm working on a page for an e-commerce site that has a form than lists items in an order placed by a customer. The form serves two purposes: to edit
and save the details of the items (i.e. number of items, price, etc.) and to split the order (i.e. select certain items to remove from the order and
use to create a new separate order). Each item has a checkbox next to it, and the name for the checkbox is "name[]" so an array of the checked items
is created and passed to the processing script. The logic I want to use to determine if the items are being saved or being split out is by looking at
the $name array. However, if I try something like "if ($_POST['name'])" and none of the checkboxes are checked, I get an Undefined Index error (it
works fine if there are items checked). What is a valid way to check to see if the $name array exists so I know which action to take?

Smarty: Checkbox Validation
I have smth. like this:

file.php:
<?php

SmartyValidate::connect($smarty);
//SmartyValidate::register_form('register');

$smarty->assign('nl_id',0);
$smarty->assign('nl_sel',$Fnewsletter);
$smarty->assign('nl_name','Fnewsletter');
$smarty->assign('pp_id',0);
$smarty->assign('pp_sel',$pp);
$smarty->assign('pp_name','Fnewsletter');

if(SmartyValidate::is_valid($_POST) == true) {
// Register

} else {
// Form displayed with hints ex. "You forget e-mail"
$smarty->assign($_POST);
$smarty->display("register_form.tpl");
}

?>

Theme.tpl

{$duplikacja_usera}
<p>{validate field="Flogin" criteria="notEmpty" message=" Podaj
login "}</p>
<p>{validate field="Fhaslo" criteria="notEmpty" message=" Podaj
hasL,o "}</p>
<p>{validate field="Fhaslo" criteria="isEqual"
field2="Fhaslorepeat" message=" HasL,o nie zgadza siÄ™ z
powyLLszym "}</p>
<p>{validate field="Fimie" criteria="notEmpty" message=" Podaj imie
"}</p>
<p>{validate field="Fnazwisko" criteria="notEmpty" message=" Podaj
nazwisko "}</p>
<p>{validate field="Fmail" criteria="isEmail" message=" Podaj
poprawny e-mail "}</p>
<p>{validate field="Fulica" criteria="notEmpty" message=" Podaj
ulice "}</p>
<p>{validate field="Fnumer" criteria="notEmpty" message="Podaj
numer domu "} </p>
<p>{validate field="Fkod" criteria="notEmpty" message=" Podaj kod
pocztowy "}</p>
<p>{validate field="Fmiasto" criteria="notEmpty" message=" Podaj
miasto "}</p>
<BR>
<form name="register" onsubmit="return check(this)"
action="index.php/mode/register" method="POST">
<input type="hidden" name="akcja" value="rejestruj">
<input type="text" name="Flogin" value="{$Flogin}" maxlength="20"
class="login_in" style="width:150px"></div>
<input type="password" name="Fhaslo" maxlength="20" class=""
class="login_in" style="width:150px"></div>
<input type="password" name="Fhaslorepeat" maxlength="20" class=""
class="login_in" style="width:150px">
<input type="text" name="Fimie" value="{$Fimie}"
maxlength="20" class="login_in" style="width:150px">
<input type="text" name="Fnazwisko"
value="{$Fnazwisko}" maxlength="100" class="login_in"
style="width:150px">
{validate field="Fnazwisko" criteria="notEmpty"
message=" Podaj nazwisko "}</div>

{html_checkboxes name="Fnewsletter" values=$nl_id
selected=$nl_sel}..........

What Goes Into The Database When You Submit Via A Checkbox?
I have a simple form with a checkbox and I thought that when the box is checked and I submit to the MySQL database then the number 1 would appear in the database and if it wasn't checked then a 0 would appear. But whether it is checked or not, a 0 appears. How do I make it so that a 1 appears if the box is checked?

How To Give A Value To Non Selected Checkbox
I would like to get a value for a non selected checkbox in a form.

Imagine my form contains :

<input type='checkbox' name='t[0]' value=&#391;'>
<input type='checkbox' name='t[1]' value=&#391;'>

When I analyse $t, if first checkbox is not selected and second is, I have :
$t[0] has no value. $t[1] equals 1
and count($t) equals 1

I would like to find a way to get :
$t[0] equals 0. $t[1] equals 1
and count($t) equals 2

Checkbox Search Engine
I wanted to create a search engine with checkboxes. In my database are names of our programmers and what programming languages they can write.

I got one (.html) form and one (.php) file that searches the database. Every time I try to connect to the database, I get a blank page?! Could someone help me, I don’t know what’s wrong. Below you can find the tables and files. Code:

Form Processing With Checkbox ?
I am currently writing a webpage that displays a list of records (
each record has a checkbox associated with it) to allow users to
select any record they want to delete (much like in "hotmail" or
"yahoo" e-mail where u can select particular message to delete) ?

Anybody have any idea how to do it ?

And one more question, I like to write my page so that when the user
click on a checkbox associated with a record. That record (that row)
is highlighted (like in "hotmail"), anybody has any idea how to do it
?


Copyright © 2005-08 www.BigResource.com, All rights reserved