The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Clearing checkbox property
Discuss Clearing checkbox property in the PHP Development forum on Dev Shed. Clearing checkbox property PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 1st, 2000, 12:39 AM
|
|
Contributing User
|
|
Join Date: May 2000
Posts: 77
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
I am currently working on a phonebook system whereby people can add their own names to the database. So I also have an edit facility. Within my form however I have 3 checkboxes. What I need to know is say someone clears their checkbox, how do I get that to clear the table field?? At the moment, if they de-select the field then it adds it doesn't change the field. Also note, i created a separate column for each of the checkbox fields (they are called roles1, roles2, and roles3). I have included my code for how I can tell if the box should be checked or not. Thanks for your help.
Dave
<?php
// Check Box 1
echo "<input type='checkbox' name='roles1' value='EH&S Representative' ";
if (ereg("EH&S Representative", $myrow[roles1]))
{
# if database field value =yes then
echo "checked";
}
printf (">EH&S Representative");
?>
|

June 1st, 2000, 01:44 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
see ,,, you can find out wether user has selected the check box or not using isset() function
eg:
if (!isset(roles1)){
$roles1="Not Selected";
}
$result=mysql_query("UPDATE phonebook set roles1='$roles1'",$con);
------------------
SR -
shiju.dreamcenter.net
"The fear of the LORD is the beginning of knowledge..."
[This message has been edited by Shiju Rajan (edited June 01, 2000).]
|

June 1st, 2000, 01:51 AM
|
|
Contributing User
|
|
Join Date: May 2000
Posts: 77
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
Can you see any reason why the following script would not update my database when each of the field is past to it? I had it working earlier but have found now that nothing is being updated...
<?php
// setup database connection
$db = mysql_connect("localhost", "root");
// specify database to use
mysql_select_db("development",$db);
// specify query to use
mysql_query("UPDATE staff SET
fname = $fname,
sname = $sname,
location = $location,
dept = $dept,
report = $report,
btitle = $btitle,
phone_extension = $phone_extension,
phone_int = $phone_int,
phone_ext = $phone_ext,
fax = $fax,
phone_mob = $phone_mob,
alt_email = $alt_email,
roles1 = $roles1
roles2 = $roles2
roles3 = $roles3
WHERE fname=$fname AND sname=$sname");
print ("<font size='2' face='Frutiger, Verdana, Arial, Helvetica, sans-serif'>");
print ($fname);
echo $mysql_query;
print (" ");
print ($sname);
print ("<p>");
print ("Details have been added!");
print ("</font>");
?>
|

June 1st, 2000, 03:50 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
Query is wrong..you missed commas.
<<
roles1 = $roles1
roles2 = $roles2
roles3 = $roles3
WHERE fname=$fname AND sname=$sname
try this:
mysql_query("UPDATE staff SET
fname = $fname,
sname = $sname,
location = $location,
dept = $dept,
report = $report,
btitle = $btitle,
phone_extension = $phone_extension,
phone_int = $phone_int,
phone_ext = $phone_ext,
fax = $fax,
phone_mob = $phone_mob,
alt_email = $alt_email,
roles1 = $roles1,
roles2 = $roles2,
roles3 = $roles3,
WHERE fname=$fname AND sname=$sname");
------------------
SR -
shiju.dreamcenter.net
"The fear of the LORD is the beginning of knowledge..."
[This message has been edited by Shiju Rajan (edited June 01, 2000).]
|

June 1st, 2000, 04:13 AM
|
|
Contributing User
|
|
Join Date: May 2000
Posts: 109
Time spent in forums: < 1 sec
Reputation Power: 14
|
|
|
If this doesn't work you must put all variables between parenthesis, like:
mysql_query("UPDATE staff SET
fname = '$fname',
sname = '$sname',
location = '$location',
.
.
.
roles1 = '$roles1',
roles2 = '$roles2',
roles3 = '$roles3',
WHERE fname='$fname' AND sname='$sname'");
[This message has been edited by pwluky (edited June 01, 2000).]
|

June 1st, 2000, 04:33 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
|
If this doesn't work you must put all variables between parenthesis, like:
That is right. you should do that....
|

June 1st, 2000, 07:14 PM
|
|
Contributing User
|
|
Join Date: May 2000
Posts: 77
Time spent in forums: < 1 sec
Reputation Power: 13
|
|
|
Thanks guys, that worked the treat. I originally did have the single quotes but in my desperate attempt to sort out what was going on I took them out. All appears to be working perfectly now. Thanks again!
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|