vbcoach Posted May 17, 2016 Share Posted May 17, 2016 Hello all. I have a sports league website that is used for captains to be able to view and manipulate certain items displayed in a form format. I want to be able to hide or disable two buttons in the form; the Edit and Remove buttons based on a simple IF statement. However I am not quite being able to make this happen, as the form is outside of the PHP statement. <body> <table width="800" border="0" cellpadding="0" cellspacing="0"> <tr> <td><img src="images/BBV_CP_top.jpg" width="800" height="200"></td> </tr> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="6%" class="menu"><a href="home.php"> Home</a> </td> <td width="9%" class="menu"> <?php if {echo "<a href=editTeam.php> Edit Team </a>";}?></td> <td width="12%" class="menu"> <?php if ($team[session] == 'Summer') {echo "<a href=addPlayer.php> Add Player </a>";}?></td> <td width="63%" class="menu"><br> <?php if ($team[session] == 'Summer') {echo "<a href=editInfo.php> Edit My Information </a>";}?></td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table></td> </tr> <tr> <td><table width="765" border="0" cellspacing="1" cellpadding="1"> <?php if($info['feepaid'] == 'n') { ?> <tr> <td colspan="2" align="left" valign="top"> </td> </tr> <?php }?> <tr> <td width="37%" align="left" valign="top"><br> <table width="100%" border="0" cellpadding="2" cellspacing="0" class="grey2px"> <tr> <td colspan="2" class="dk_greyTxt"><h3><strong>Captain's Information</strong></h3></td> </tr> <tr> <td width="27%" class="dk_greyTxt"><strong>Name</strong></td> <td width="73%"><?php echo $info['cptname']; ?> </td> </tr> <tr> <td class="dk_greyTxt"><strong>Address</strong></td> <td><?php echo $info['address']; ?><br> <?php echo "$info[city], $info[state] $info[zip]"; ?> </td> </tr> <tr> <td class="dk_greyTxt"><strong>Phone</strong></td> <td><?php echo $info['phone'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>E-mail</strong></td> <td><?php echo $info['email'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Shirt Size </strong></td> <td><?php echo $info['size'] ?></td> </tr> </table> <br></td> <td width="63%" rowspan="2" align="left" valign="top"><br> <table width="100%" cellpadding="1" cellspacing="0" class="grey2px"> <tr class="dk_greyTxt"> <td colspan="6"><h3><strong>Player's Information</strong></h3></td> </tr> <tr class="dk_greyTxt"> <td width="21%"><strong>Name</strong></td> <td width="23%"><strong>E-mail</strong></td> <td width="21%"><div align="center"><strong>Shirt Size</strong></div></td> <td width="19%"> </td> <td width="16%"> </td> </tr> <?php $i=0; while($row = mssqlfetchassoc($players)) { ?> <tr <?php if($i%2 == 0) echo "class='altbg'";?> > <td><?php echo $row['name'] ?></td> <td><?php echo $row['email'] ?></td> <td align="center"><?php echo $row['pshirt'] ?></td> <td><form name="del_player<?= $row['p_id'] ?>" action="remPlayer.php" method="post" onSubmit="return(confirm('Are you sure you want to delete <?= $row['name']?>?\n\nThis cannot be reversed'))"> </form></td> <td><form name="player<?= $row['p_id'] ?>" action="editPlayer.php" method="post"> </form></td> </tr> <?php $i++; } ?> </table></td> </tr> <tr> <td align="left" valign="top"><br> <table width="100%" border="0" cellpadding="2" cellspacing="0" class="grey2px"> <tr> <td colspan="2" class="dk_greyTxt"><h3>Team Information </h3></td> </tr> <tr> <td width="27%" class="dk_greyTxt"><strong>Name</strong></td> <td width="73%"><?php echo $team['teamname']; ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>League</strong></td> <td><?php echo "$team[night] $team[type] $team[size]s"; ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Division</strong></td> <td><?php echo $team['division'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Shirt Color </strong></td> <td><?php echo $team['shirtcolor'] ?></td> </tr> <tr> <td class="dk_greyTxt"><strong>Registration Date </strong></td> <td><?php echo $team['reg_start'] ?></td> </tr> <?php if($info['feepaid'] == 'n') { ?> <?php } else { ?> <tr> <td class="dk_greyTxt"><strong>Registration Completed </strong></td> <td><?php echo $team['reg_done'] ?></td> </tr> <?php } ?> <?php mssqlclose(); ?> <tr> <td class="dk_greyTxt"><strong>Record </strong></td> <td> </td> </tr> </table></td> </tr> </table></td> </tr> </table> <br> </body> Under the Players table, there is an Edit and Remove button. I would like to hide this button based upon a PHP statement that looks a bit like this: <?php if ($team[session] == 'Summer')... Basically we are in the Spring session, thus at this point in the season, I do not want teams to be able to edit, add, or remove any player information. However the same database is used for both Spring and Summer registrations. So any help incorporating this php statement to hide these buttons would be greatly appreciated! -J Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted May 17, 2016 Share Posted May 17, 2016 (edited) Well, if you are using sessions, it is easy. Just put $_SESSION['season'] = 'Summer' or $_SESSION['season'] = 'Spring' in the header of the your application and then use the if statements to check the value of the $_SESSION variable. If you don't want to manually update the value of the season session, you can put it inside a switch statement Edited May 17, 2016 by Stefany93 Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 17, 2016 Share Posted May 17, 2016 (edited) You haven't posted anything about your database which is really where this starts. You should have a db column is_summer with a one or zero. Then in your code if (row['is_summer']){ // button code } Edited May 17, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted May 17, 2016 Share Posted May 17, 2016 You haven't posted anything about your database which is really where this starts. You should have a db column is_summer with a one or zero. Then in your code if (row['is_summer']){ // button code } He said he can't modify the DB. To the OP -> Remove the inline stylings. Use CSS. It will be a pain to modify the code later on. Quote Link to comment Share on other sites More sharing options...
benanamen Posted May 17, 2016 Share Posted May 17, 2016 He said he can't modify the DB. Really? Where does it say that? Quote Link to comment Share on other sites More sharing options...
vbcoach Posted May 17, 2016 Author Share Posted May 17, 2016 Let me try this again. In the middle of my page, there is a form statement that creates buttons to push. I would like to create an "IF" statement to display or not display these buttons. In my code I use "session" but it really means "season" as in Spring or Summer. So if the "season" = Summer, then display these buttons. The basic code for these buttons looks like this: <?php if($row['ptsordered'] == '') { ?> <form name="player<?= $row['p_id'] ?>" action="editPlayer.php" method="get"> <input type="hidden" name="p" value="<?= $row['p_id'] ?>"> <input name="Submit" type="submit" class="button" value="Edit"> </form> <?php } ?> </td> <td><form name="del_player<?= $row['p_id'] ?>" action="remPlayer.php" method="post" onSubmit="return(confirm('Are you sure you want to delete <?= $row['name']?>?\n\nThis cannot be reversed'))"> <input type="hidden" name="p" value="<?= $row['p_id'] ?>"> <input type="hidden" name="t" value="<?= $id ?>"> <input name="Submit" type="submit" class="button" value="Remove"> </form></td> </tr> <?php $i++; } ?> So I need help with a PHP statement that says if "session = 'Summer" then ..." displays the buttons, if not, the buttons are not displayed. Does this make sense now? Sorry for the confusion. Quote Link to comment Share on other sites More sharing options...
Solution vbcoach Posted May 17, 2016 Author Solution Share Posted May 17, 2016 It took a lot or research and editing, but I found my answer. Thanks all. Quote Link to comment 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.