ag3nt42 Posted July 8, 2008 Share Posted July 8, 2008 hello everyone, I need your help again... I've got a form that I'm running through a series of different things for.. The problematic one is this.. I have a loop where I bring in the variables... then echo them out to test that they are there.. which they echo out just fine.. then right after I am echoing them again as values in a form.. this time they are gone.. I can't figure out what is happening to them from point A to point B heres the code... SUBMITTED FORM: <form action='../Ca_info/Ccd_info.php' method='post'> First Department <input type='hidden' value='123' name='Cat1' /> <input type='hidden' value='First Department' name='CatD1' /> <input type='hidden' value='1' name='CatT1' /> <input type='hidden' value='40' name='CatH1' /> <input type='hidden' value='1' name='ID1' /> <input type='submit' value='Details' name='action' /> <input type='submit' value='Delete' name='action' /> </form> submitted to this page: the code: //*LOOP AVAILABLE CATS*// for($x=1;$x<=$count;$x++) { if (!(isset($_POST['Cat'.$x]))){$Cat[$x]='';}else{$Cat[$x]=$_POST['Cat'.$x];} if (!(isset($_POST['CatD'.$x]))){$CatD[$x]='';}else{$CatD[$x]=$_POST['CatD'.$x];} if (!(isset($_POST['CatT'.$x]))){$CatT[$x]='';}else{$CatT[$x]=$_POST['CatT'.$x];} if (!(isset($_POST['CatH'.$x]))){$CatH[$x]='';}else{$CatH[$x]=$_POST['CatH'.$x];} if (!(isset($_POST['ID'.$x]))){$ID[$x]='';}else{$ID[$x]=$_POST['ID'.$x];} echo($Cat[$x].$CatD[$x].$CatT[$x].$CatH[$x].$ID[$x]); //DELETE QUERY $CatDelete[$x]="DELETE FROM [".$database."] WHERE ID='".$ID[$x]."'"; } then the processing code: //WHICH ACTION? if(!(isset($_POST['action']))){$action='';}else{$action=$_POST['action'];} echo($action); //SHOW DETAILS if($action=='Details') { for($x=1;$x<=$count;$x++) { echo(" <h1>".$CatD[$x]."</h1> <fieldset><legend>Edit/Details</legend> <form action='Ccd_info.php' method='post'> <table> <tr> <td><label>Category/Department #: </label></td> <td><input type='text' value='".$Cat[$x]."' name='UCat#' /></td> </tr> <tr> <td><label>Description: </label></td> <td><input type='text' value='".$CatD[$x]."' name='UCatD' /></td> </tr> <tr> <td><label>Time Slots: </label></td> <td><input type='text' value='".$CatT[$x]."' name='UCatT' /></td> </tr> <tr> <td><label>Hours: </label></td> <td> <input type='text' value='".$CatH[$x]."' name='UCatH' /> <input type='hidden' value='".$ID[$x]."' name='UID' /> </td> </tr> <tr> <td colspan='2'> </td> </tr> <tr> <td><input type='reset' value='reset' name='action' /></td> <td><input type='submit' value='Update' name='action' /></td> </tr> </table> </form> </fieldset> "); } } Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/ Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 the funny thing about it is.. even with using the EXACT same code... only two of the values will populate in the inputs... the rest of them are errored out with "uninitialized offset 1" which.. using the EXACT same code.. to echo them before hand works just fine.. So i duno here is all the code in its page form.. (with the rest of the code): <?php /////////////////////////////////// //*******************************// //* Snatch Database Information *// //*******************************// /////////////////////////////////// $database=$tblpre."cat_dep"; $SQL="SELECT Description FROM [".$database."]"; $result=mssql_query($SQL)or die(mssql_error()); $y=0; $count=mssql_num_rows(mssql_query($SQL)); //STOP BITCHING $Z=array(); while($row=mssql_fetch_row($result)) { $Z[$y]=$row[0]; $y++; } ///////////////////// //*****************// //* HARVEST INPUT *// //*****************// ///////////////////// //INTIALIZE ARRAYS $Cat=array(); $CatD=array(); $CatT=array(); $CatH=array(); $ID=array(); $CatUpdate=array(); $CatDelete=array(); $CatDetail=array(); //*LOOP AVAILABLE CATS*// for($x=1;$x<=$count;$x++) { if (!(isset($_POST['Cat'.$x]))){$Cat[$x]='';}else{$Cat[$x]=$_POST['Cat'.$x];} if (!(isset($_POST['CatD'.$x]))){$CatD[$x]='';}else{$CatD[$x]=$_POST['CatD'.$x];} if (!(isset($_POST['CatT'.$x]))){$CatT[$x]='';}else{$CatT[$x]=$_POST['CatT'.$x];} if (!(isset($_POST['CatH'.$x]))){$CatH[$x]='';}else{$CatH[$x]=$_POST['CatH'.$x];} if (!(isset($_POST['ID'.$x]))){$ID[$x]='';}else{$ID[$x]=$_POST['ID'.$x];} echo($Cat[$x].$CatD[$x].$CatT[$x].$CatH[$x].$ID[$x]); //DELETE QUERY $CatDelete[$x]="DELETE FROM [".$database."] WHERE ID='".$ID[$x]."'"; } //HARVEST SUBMIT CATS if(!(isset($_POST['CatD#']))){$CatDx='';}else{$CatDx=$_POST['CatD#'];} if(!(isset($_POST['CatD']))){$CatD='';}else{$CatD=$_POST['CatD'];} if(!(isset($_POST['CatTs']))){$CatTs='';}else{$CatTs=$_POST['CatTs'];} if(!(isset($_POST['CatH']))){$CatH='';}else{$CatH=$_POST['CatH'];} //HARVEST UPDATE CATS if(!(isset($_POST['UCat#']))){$UCat='';}else{$UCat=$_POST['UCat#'];} if(!(isset($_POST['UCatD']))){$UCatD='';}else{$UCatD=$_POST['UCatD'];} if(!(isset($_POST['UCatT']))){$UCatT='';}else{$UCatT=$_POST['UCatT'];} if(!(isset($_POST['UCatH']))){$UCatH='';}else{$UCatH=$_POST['UCatH'];} if(!(isset($_POST['UID']))){$UID='';}else{$UID=$_POST['UID'];} ///////////////////// //*****************// //* SQL VARIABLES *// //*****************// ///////////////////// $CatInsert="INSERT INTO [".$database."] (cat_dep#, Description, TimeSlots, Hours) VALUES ('".$CatDx."', '".$CatD."', '".$CatTs."', '".$CatH."')"; $CatUpdate="UPDATE [".$database."] SET cat_dep#='".$UCat."', Description='".$UCatD."', TimeSlots='".$UCatT."', Hours='".$UCatH."' WHERE ID='".$UID."'"; ///////////////////// //*****************// //* SQL INJECTION *// //*****************// ///////////////////// $Success=0; $Fail=0; //WHICH ACTION? if(!(isset($_POST['action']))){$action='';}else{$action=$_POST['action'];} echo($action); //SHOW DETAILS if($action=='Details') { for($x=1;$x<=$count;$x++) { echo(" <h1>".$CatD[$x]."</h1> <fieldset><legend>Edit/Details</legend> <form action='Ccd_info.php' method='post'> <table> <tr> <td><label>Category/Department #: </label></td> <td><input type='text' value='".$Cat[$x]."' name='UCat#' /></td> </tr> <tr> <td><label>Description: </label></td> <td><input type='text' value='".$CatD[$x]."' name='UCatD' /></td> </tr> <tr> <td><label>Time Slots: </label></td> <td><input type='text' value='".$CatT[$x]."' name='UCatT' /></td> </tr> <tr> <td><label>Hours: </label></td> <td> <input type='text' value='".$CatH[$x]."' name='UCatH' /> <input type='hidden' value='".$ID[$x]."' name='UID' /> </td> </tr> <tr> <td colspan='2'> </td> </tr> <tr> <td><input type='reset' value='reset' name='action' /></td> <td><input type='submit' value='Update' name='action' /></td> </tr> </table> </form> </fieldset> "); } } //DELETE CAT elseif($action=='Delete') { for($x=1;$x<=$count;$x++) { if($Cat[$x]=='') { echo(''); } else { if(mssql_query($CatDelete[$x])) { echo("<font color='green'>".$CatD[$x]." Deleted Successfully!</font><br />"); $Success++; } else { echo("<font color='red'>".$CatD[$x]." Delete FAILED!</font>".mssql_error()."<br />"); $Fail++; } } } } //SUBMIT CAT if($action=='Submit') { if(mssql_query($CatInsert)) { echo("<font color='green'>".$CatD." Successfully Submitted!</font><br />"); $Success++; } else { echo("<font color='red'>".$CatD." Failed to Submit!</font>".mssql_error()."<br />"); $Fail++; } } //UPDATE CAT elseif($action=='Update') { if(mssql_query($CatUpdate)) { echo("<font color='green'>".$UCatD." Successfully Updated!</font><br />"); $Success++; } else { echo("<font color='red'>".$UCatD." Failed to Update!</font>".mssql_error()."<br />"); $Fail++; } } // WAS IT SUCCESSFUL? if($Success>=1) { echo("<meta http-equiv='refresh' content='3;url=http://".$domain.$sPath."admin/Edits/CategoriesNDepartments.php'>"); //Redirect } elseif($Fail>=0) { echo('ERROR NO GO'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584439 Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 where are you setting $count?? Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584441 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 <?php /////////////////////////////////// //*******************************// //* Snatch Database Information *// //*******************************// /////////////////////////////////// $database=$tblpre."cat_dep"; $SQL="SELECT Description FROM [".$database."]"; $result=mssql_query($SQL)or die(mssql_error()); $y=0; $count=mssql_num_rows(mssql_query($SQL)); //STOP BITCHING $Z=array(); while($row=mssql_fetch_row($result)) { $Z[$y]=$row[0]; $y++; } ?> there is only one available cat in the database Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584443 Share on other sites More sharing options...
craygo Posted July 8, 2008 Share Posted July 8, 2008 sorry my bad Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584446 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 sorry my bad its ok.. no worries..happens Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584448 Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 just before you start to echo the table, do a print_r() on those arrays (outside the for loop). I'm curious to see if they are set and what they are set to Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584452 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 code: print_r("<br />".$Cat.$CatD.$CatT.$CatH.$ID."<br />"); result: ArrayArrayArrayArrayArray hope i did that right i never use print Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584457 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 ok here we goo.. code: <br /> <?php print_r($Cat); ?> <br /> <?php print_r($CatD); ?> <br /> <?php print_r($CatT); ?> <br /> <?php print_r($CatH); ?> <br /> <?php print_r($ID); ?> <br /> result: Array ( [1] => 123 ) Array ( [1] => First Department ) Array ( [1] => 1 ) Array ( [1] => 40 ) Array ( [1] => 1 ) this is done just after the loop Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584465 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 god yes.. i frikin found the problem.. anyone see a problem here between these? <?php //HARVEST SUBMIT CATS if(!(isset($_POST['CatD#']))){$CatDx='';}else{$CatDx=$_POST['CatD#'];} if(!(isset($_POST['CatD']))){$CatD='';}else{$CatD=$_POST['CatD'];} if(!(isset($_POST['CatTs']))){$CatTs='';}else{$CatTs=$_POST['CatTs'];} if(!(isset($_POST['CatH']))){$CatH='';}else{$CatH=$_POST['CatH'];} ?> and: <?php if (!(isset($_POST['Cat'.$x]))){$Cat[$x]='';}else{$Cat[$x]=$_POST['Cat'.$x];} if (!(isset($_POST['CatD'.$x]))){$CatD[$x]='';}else{$CatD[$x]=$_POST['CatD'.$x];} if (!(isset($_POST['CatT'.$x]))){$CatT[$x]='';}else{$CatT[$x]=$_POST['CatT'.$x];} if (!(isset($_POST['CatH'.$x]))){$CatH[$x]='';}else{$CatH[$x]=$_POST['CatH'.$x];} if (!(isset($_POST['ID'.$x]))){$ID[$x]='';}else{$ID[$x]=$_POST['ID'.$x];} ?> I was unwillingly resetting the array.. when I was pulling in the other inputs.. if I change the variables for the SUBMIT pull in.. then everything works. hehe.. apparently "$CatD[$x]" and "$CatD" are the same.. lol oops thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584469 Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 that would do it. You may consider learning tertiary notation. It would clean up those statements and possibly make stuff like that easier to spot. if (!(isset($_POST['Cat'.$x]))){$Cat[$x]='';}else{$Cat[$x]=$_POST['Cat'.$x];} becomes $Cat[$x] = isset($_POST['Cat'.$x]) ? $_POST['Cat'.$x] : ''; syntax is: Variable = test ? val_if_true : val_if_false Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584484 Share on other sites More sharing options...
slushpuppie Posted July 8, 2008 Share Posted July 8, 2008 You may consider learning tertiary notation. It would clean up those statements and possibly make stuff like that easier to spot. not to be a nit-picker, but isn't it 'ternary', not 'tertiary'? Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584493 Share on other sites More sharing options...
mbeals Posted July 8, 2008 Share Posted July 8, 2008 you're right, it is ternary Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584496 Share on other sites More sharing options...
DarkWater Posted July 8, 2008 Share Posted July 8, 2008 You may consider learning tertiary notation. It would clean up those statements and possibly make stuff like that easier to spot. not to be a nit-picker, but isn't it 'ternary', not 'tertiary'? Yeah, it's ternary. I've only used the word tertiary when talking about consumers in a food chain. Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584497 Share on other sites More sharing options...
ag3nt42 Posted July 8, 2008 Author Share Posted July 8, 2008 lol..yea I'm sure there are alot of things I can learn to make things easier.. just have to wait till I come across them.. thanks for the tip guys. Quote Link to comment https://forums.phpfreaks.com/topic/113730-solved-disappearing-values/#findComment-584583 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.