|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
checkboxes (URGENT)
hi,
its on checkboxes again...i want to accept multiple values from the checkboxes and insert in in the table..i tried the $_POST and array as suggested in the forum but i got the following error. Warning: Invalid argument supplied for foreach() in /home/alifya/public_html/wedprac/edit.php on line 26 someone please help me...i am posting my entire code <? // This page will handle both creation of new records, and update // of existing records. include "connection.php"; // Here is where you process EDIT/UPDATE commands. if ($update) { $query = "UPDATE users SET firstName="$firstName", lastName="$lastName", dateModified=now(), primaryEmail="$primaryEmail", idValue="$idValue", idType="$idType" where ID=$ID;"; $res = db_query($query); foreach($_POST['groupID'] as $value) { $query5="INSERT into users_in_groups values ($ID, $value);"; $res5 = db_query($query5); } //header("Location: view.php?ID=$ID&feedbackCode=3"); exit(); } //execute sql command to update the id (remember that we get the ID from the hidden variable else if ($add) { $query = "INSERT into users(firstName,lastName, dateCreated, idValue, primaryEmail, idType) values ("$firstName", "$lastName", now(), "$idValue", "$primaryEmail", "$idType" );"; $res = db_query($query); $lastID = mysql_insert_id(); header("Location: view.php?ID=$lastID&feedbackCode=2"); exit(); } $new=false; if ($ID) { $query = "SELECT firstName, lastName,primaryEmail, dateCreated, dateModified, idValue, idType FROM users WHERE ID=$ID;"; $res = db_query($query); $query1="SELECT userID, ID, groupID from users, users_in_groups where userID=ID and ID=$ID;"; $res1 = db_query($query1); while ($row=db_fetch_array($res)) { extract($row); while ($row1=db_fetch_array($res1)) { extract($row1); echo $groupID; if ($groupID==1){ $gflag="checked";} else if ($groupID==2){ $gflag2="checked";} else if ($groupID==3){ $gflag3="checked";} else {$flag="";} } } } else { $new=true; } ?> <H1><?=($new==true?"Create new record":"Editing record $ID")?></H1> <FORM action="<?=$PHP_SELF?>" method="get"> <!-- here, send a hidden variable with the ID (if it's not a new record)--> <INPUT type="hidden" name="ID" value="<?=(($new==true)?"":$ID)?>"> <INPUT type="hidden" name="idType" value="<?=(($new==true)?"":$idType)?>"> First Name : <INPUT type="text" name="firstName" value="<?=(($new==true)?"Enter new First Name ":$firstName)?>"><BR><BR> Last Name : <INPUT type="text" name="lastName" value="<?=(($new==true)?"Enter new Last Name ":$lastName)?>"><BR><BR> Primary Email : <INPUT type="text" name="primaryEmail" value="<?=(($new==true)?"Enter new Email Address ":$primaryEmail)?>"><BR><BR> ID Number : <INPUT type="text" name="idValue" maxlength="9" size="9" value="<?=(($new==true)?"Enter new ID ":$idValue)?>"><BR><BR> <? if ($idType==1){ $flag="checked";} else if ($idType==2){ $flag2="checked";} else if ($idType==3){ $flag3="checked";} else {$flag="";} ?> ID TYPE : <INPUT type="radio" name="idType" value="1" <? echo $flag;?>>BRUINID <INPUT type="radio" name="idType" value="2" <? echo $flag2;?>>PASSPORT <INPUT type="radio" name="idType" value="3" <? echo $flag3;?>>DRIVERS LICENSE <BR><BR> GROUP TYPE : <INPUT type="checkbox" name="groupID[]" value="1" <? echo $gflag;?>>STUDENT <INPUT type="checkbox" name="groupID[]" value="2" <? echo $gflag2;?>>PROFESSOR <INPUT type="checkbox" name="groupID[]" value="3" <? echo $gflag3;?>>VISITING FACULTY <br><br> <input type="submit" name="<?=($new==true?"add":"update")?>" value="<?=($new==true?"Add new record":"Update this record")?>"> </FORM> <FORM action="search.php" method="get"> <INPUT type="submit" name= "RetSearch" value="Return to Search Page"> </FORM> |
|
#2
|
||||
|
||||
|
RE: checkboxes (URGENT)
Checkboxes only have a value if they are checked, so if none of the groupID[] checkboxes are checked, $_POST['groupID'] will be NULL and not an array.
|
|
#3
|
|||
|
|||
|
RE: checkboxes (URGENT)
hello,
but they are checked....i still get the error alifya |
|
#4
|
|||
|
|||
|
RE: checkboxes (URGENT)
again, see this tutorial...
www.phpbuilder.com/columns/laflamme20001016.php3 |
|
#5
|
|||
|
|||
|
RE: checkboxes (URGENT)
hi zombie,
i tried the tutorial..it gives me an error at foreach...dunno why??? |
|
#6
|
|||
|
|||
|
RE: checkboxes (URGENT) thanks codegirl
hi code,
it worked great!! however it works only for EDIT... when i use the same technique for adding a fresh one it does not work... what should i do?? thanks |
|
#7
|
|||
|
|||
|
RE: checkboxes (URGENT)
hi,
even i am havign the same problem. was trying the tutorial and checkboxes and dont know how to get add to work |
|
#8
|
|||
|
|||
|
RE: checkboxes (URGENT)
hi,
heres the users table defination: CREATE TABLE `users` ( `ID` int(11) NOT NULL auto_increment, `username` varchar(16) NOT NULL default '', `password` varchar(32) NOT NULL default '', `firstName` varchar(255) NOT NULL default '', `lastName` varchar(255) NOT NULL default '', `primaryEmail` varchar(255) NOT NULL default '', `dateCreated` datetime NOT NULL default '0000-00-00 00:00:00', `dateModified` datetime NOT NULL default '0000-00-00 00:00:00', `idType` int(11) NOT NULL default '0', `idValue` varchar(64) NOT NULL default '', PRIMARY KEY (`ID`) ) TYPE=MyISAM i have another table called users_in_groups which takes in the ID of the user and also the groupID as the professor or student...as i told you...it worked great for edit...but when i add a user as a professor using the same functionality as edit it does not do it. thanks |
|
#9
|
|||
|
|||
|
RE: checkboxes (URGENT)
i am still stuck. just cant gt add to work....any solutions
|
|
#10
|
|||
|
|||
|
RE: checkboxes (URGENT)
the problem is the insert works fine with the other fields...but when i insert into the checkboxes it doesnt get inserted but when i edit the same record it works again.
the following is the code i am using. Edit works great but add doesnt. <? // This page will handle both creation of new records, and update // of existing records. include "connection.php"; // Here is where you process EDIT/UPDATE commands. if ($update) { $query = "UPDATE users SET firstName="$firstName", lastName="$lastName", dateModified=now(), primaryEmail="$primaryEmail", idValue="$idValue", idType="$idType" where ID=$ID;"; $res = db_query($query); $query2= "DELETE FROM users_in_groups where userID=$ID;"; $res2 = db_query($query2); if (is_array($_POST['groupID'])) { foreach($_POST['groupID'] as $value) { $query6="INSERT into users_in_groups values ($ID, $value);"; $res6 = db_query($query6); } } header("Location: view.php?ID=$ID&feedbackCode=3"); exit(); } //execute sql command to update the id (remember that we get the ID from the hidden variable else if ($add) { $query = "INSERT into users(firstName,lastName, dateCreated, idValue, primaryEmail, idType) values ("$firstName", "$lastName", now(), "$idValue", "$primaryEmail", "$idType" );"; $res = db_query($query); if (is_array($_POST['groupID'])) { foreach($_POST['groupID'] as $value) { $query7="INSERT into users_in_groups values ($ID, $value);"; $res7 = db_query($query7); } } $lastID = mysql_insert_id(); header("Location: view.php?ID=$lastID&feedbackCode=2"); exit(); } $new=false; if ($ID) { $query = "SELECT firstName, lastName,primaryEmail, dateCreated, dateModified, idValue, idType FROM users WHERE ID=$ID;"; $res = db_query($query); $query1="SELECT userID, ID, groupID from users, users_in_groups where userID=ID and ID=$ID;"; $res1 = db_query($query1); while ($row=db_fetch_array($res)) { extract($row); while ($row1=db_fetch_array($res1)) { extract($row1); echo $groupID; if ($groupID==1){ $gflag="checked";} else if ($groupID==2){ $gflag2="checked";} else if ($groupID==3){ $gflag3="checked";} else {$flag="";} } } } else { $new=true; } ?> <H1><?=($new==true?"Create new record":"Editing record $ID")?></H1> <FORM action="<?=$PHP_SELF?>" method="POST"> <!-- here, send a hidden variable with the ID (if it's not a new record)--> <INPUT type="hidden" name="ID" value="<?=(($new==true)?"":$ID)?>"> <INPUT type="hidden" name="idType" value="<?=(($new==true)?"":$idType)?>"> First Name : <INPUT type="text" name="firstName" value="<?=(($new==true)?"Enter new First Name ":$firstName)?>"><BR><BR> Last Name : <INPUT type="text" name="lastName" value="<?=(($new==true)?"Enter new Last Name ":$lastName)?>"><BR><BR> Primary Email : <INPUT type="text" name="primaryEmail" value="<?=(($new==true)?"Enter new Email Address ":$primaryEmail)?>"><BR><BR> ID Number : <INPUT type="text" name="idValue" maxlength="9" size="9" value="<?=(($new==true)?"Enter new ID ":$idValue)?>"><BR><BR> <? if ($idType==1){ $flag="checked";} else if ($idType==2){ $flag2="checked";} else if ($idType==3){ $flag3="checked";} else {$flag="";} ?> ID TYPE : <INPUT type="radio" name="idType" value="1" <? echo $flag;?>>BRUINID <INPUT type="radio" name="idType" value="2" <? echo $flag2;?>>PASSPORT <INPUT type="radio" name="idType" value="3" <? echo $flag3;?>>DRIVERS LICENSE <BR><BR> GROUP TYPE : <INPUT type="checkbox" name="groupID[]" value="1" <? echo $gflag;?>>STUDENT <INPUT type="checkbox" name="groupID[]" value="2" <? echo $gflag2;?>>PROFESSOR <INPUT type="checkbox" name="groupID[]" value="3" <? echo $gflag3;?>>VISITING FACULTY <br><br> <input type="submit" name="<?=($new==true?"add":"update")?>" value="<?=($new==true?"Add new record":"Update this record")?>"> </FORM> <FORM action="search.php" method="get"> <INPUT type="submit" name= "RetSearch" value="Return to Search Page"> </FORM> |
|
#11
|
|||
|
|||
|
RE: checkboxes (URGENT)
What i mean is when i update the record the checkbox as well as th eother fields work perfect but when i add only the other fields insert statement works ...the checkbox thing doesnt even thought i am using the same code as in edit
thanks in advance...i am really stuck at this one |
|
#12
|
||||
|
||||
|
RE: checkboxes (URGENT)
it could be not working because of the checkbox not showing up when not checked. If you check every box and insert does it work?
B |
|
#13
|
|||
|
|||
|
RE: checkboxes (URGENT)
even when i check every checkbox and add..it doesnt get added....
however edit works...like if there was one checkbox already checked and i uncheck that and check another one..then it works fine |
|
#14
|
||||
|
||||
|
RE: checkboxes (URGENT)
echo your submit value so you can see what you are passing and also place an echo inside each if to check if you are actually reaching the appropriate section.
B |
|
#15
|
|||
|
|||
|
RE: checkboxes (URGENT)
yes..all sections r workign fine...except the checkbox multiple insert in add
|
![]() |
| Viewing: Codewalkers Forums > PHP Related > PHP Coding > checkboxes (URGENT) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |