PHP - Need Help Adding Conditional Url
Hello.
I have a sports league and the captain's page has a menu bar allowing links to sub pages. I would like to only add the URL part if a condition is met. In my database I have a league field called "session" for Spring or Summer sessions.
The menu bar has 5 simple columns for hyperlinks:
Home | Edit Team | Add Player | Edit My Information | Log Out |
What I would like to do is to only display say the "Edit Team" with hyperlink if the league session = "Summer" (that was Spring teams cannot edit their information at this point in time). I am trying to create an IF-Else statement, but can't quite get it right. I am a novice PHP coder, so I could really use some help. Here is the current code for this short section:
<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">Edit Team </a></td> <td width="12%" class="menu">Add Player</td> <td width="63%" class="menu">Edit My Information</a> </td> <td width="10%" class="menu"><a href="logout.php">Log Out </a></td> </tr> </table>How can I create "Edit Team" to be a hyperlink ONLY IF the condition (league = Summer) is TRUE? $team is the query that returns the league results from the MSSQL query. Thanks in advance for your help. Similar TutorialsHi,
I have a website that is 80% done when my programmer dropped the ball. I am trying to get it all to work, but have only rudimentary knowledge on what I am doing thus far and need a bit of help, please.
I have a couple of popups links that writes a reminder to check the size of necks and arms at the top of certain pages.
One of my product groups is called Collars and Armbands
which consists of 1 x category "Collars and Armbands" whic has 2 x Subcategories which are "Collars" and "Armbands" if I click on the "Collars and Armbands" tab, it displays all the contents of both subcategories Collars and Armbands, as expected. It displays the popup links for both subcategories. I don't want the popups to appear on the "Collars and Armbands" page but only on the individual "Collars" or "Armbands" pages if I click on Collars or Armbands subcategory tabs it displays the single popup link for that category. (which is what I want it to do) The problem lies in the category and subcategory names which I can't really change without making it non-logical for the customer. this the code that makes is happen if ( substr_count($sectionname,'Collars')>0 || substr_count($productname,'Collar')>0 ) { echo '<p class="measurelink noprint">Remember to <a href="neckmeasurepop.php" class="lnkpopup sllink" title="click for popup measuring instructions" onclick="slf_popupwin();return false;">Measure Your Collar Size !</a></p>'; } My question is, is there a way to set a condition that I can use for this code that says "if the $sectionname = "Collars" but NOT "Collars and Armbands" and $productname = "Collar" then display the popup link "neckmeasurepop.php". I had considered renaming the base category to something else, but that would just make things confusing for the customers. Cheers and thanks in advance Hi, I've written a conditional statement to give my body tag a unique ID, depending on three conditions. (body id="red" etc..) The statement does indeed work when tested, but dreamweaver is highlighting the conditional in yellow - So I'm wondering if there is an alternate (and perhaps cleaner) way of writing the following.. It's for a joomla site btw.. (I've spread the code out a little here, so it's easier for you guys to see what I'm doing) Code: [Select] <body <?php if($this->countModules('headerlow')) : ?> id="up" <?php endif; ?> <?php if (JRequest::getVar('Itemid')==104) { ?> id="red" <? } else {?> id="low" <? } ?> > i wanna put condition that if ($signupbonus > 0.00) then following should not be executed <font size="3" color="red"><b>Referral bonus: <font color="green" size="4">$<? echo $signupbonus; ?></font></b></font><br><br> please help I have a problem when trying to query the table closed_mbl. I want to return the COUNT of all records that contain the locations below while excluding all these records that contain anything else besides AIR. How would I do this? Right now it returns the count of everything from all these locations. The field "method" is ignored. SELECT COUNT(*) FROM closed_mbl WHERE location = 'ALL' OR location = 'AUCKLAND' OR location = 'BRAZIL' OR location = 'DALIAN' OR location = 'EXPORT' OR location = 'GALWAY' OR location = 'ISUNICOV' OR location = 'KOLIN' OR location = 'SGALWAY' OR location = 'SHANNON' OR location = 'SOMI' OR location = 'SUZHOU' OR location = 'UNICOV' OR location = 'WUJIANG' OR location = 'WUJIANGCC' AND method = 'AIR' Hi, I asked a question about Tokens earlier. After debugging I've found the reason as to why my program isn't working. It's related to this statement: if($token == $_SESSION['token']) { ........; return true; }$token is generated in form using md5(uniqid()). When I echo both $token and $_SESSION['token'] before the if statement they both turn out to be the same. Yet for some reason the if statement is not being satisfied and is not returning true as it's supposed to do. (I've tried $token === $_SESSION['token'] as well.) I don't know if some kind of type casting or other is required for the conditional statement to work. Would be grateful for any suggestions. Edited by mac_gyver, 30 October 2014 - 10:53 PM. removed links from copied text I have a membership directory that I've been working with for a long time, and recent server upgrades with MySQL, PHP, etc. forced me to do some recoding. While I was doing that, I wanted to try and make some improvements. I must give a brief description of the intent, and then the results I got, so someone can sort out the problem for me. I have a query that selects all "Agent" members, then orders them by County, then by Company Name. What I am trying to do is create a new heading in my list every time the County information changes as the list is sorted and output to my table.
I am going to attache 2 .php files with my code. The agent_member_list.php is the original code that pulls all of the members properly, and results can be viewed he http://www.nmlta.org...member_list.php
The agent2_member_list.php is where I'm trying to insert the new conditional statement to print my County headings when a new County is encountered in the results. The heading actually works, and changes correctly, but the problem is that the first member entry in every county is not printed in the output. I know the query is correct, so I'm sure I've got the conditional "if" for checking County field wrong, or misplaced. Here is the link to it: http://www.nmlta.org...member_list.php
I'm hoping someone can spot my error pretty quickly, I only dabble in this very rarely. Thanks for any help!
Attached Files
agent2_member_list.php 5.06KB
3 downloads
agent_member_list.php 4.82KB
2 downloads I would like to have a script that would check certain parameters and if none of them returns TRUE, execute a set of codes. So the idea is somehow like if...else(). Code: [Select] <?php // trying to put if() directly within if() if ( // checking of variables if (!isset($transaction)) { echo '<font color="#FF0000">Type of transaction is not set.</font>'. '<br />'; } else { if ($transaction == 'sell') { if (empty($BV)) { echo '<font color="#FF0000">Book value is not set.</font>'. '<br />'; } } } if (empty($stock)) { echo '<font color="#FF0000">Stock symbol is not set.</font>'. '<br />'; } if (empty($price)) { echo '<font color="#FF0000">Price per share is not set.</font>'. '<br />'; } if (empty($volume)) { echo '<font color="#FF0000">Volume of shares is not set.</font>'. '<br />'; } ) { echo 'Go back and fill out necessary fields.'; } // if none of the above parameters returns TRUE else { echo 'Copy and paste the following in the email that you would be submitting.' </tr> <tr> <td> switch ($transaction) { case 'buy': include('calc_buy.php'); break; case 'sell': include('calc_sell.php'); break; default: echo '<font color="#FF0000"><b>If you see this message there is something wrong with your session. Please send us a feedback with the details of your session before seeing this message.</b></font>'; } } ?> This code returns an error and as I understand the error, it is because of if (if ()). How can I make it work? Thanks in advance! Hello, I am trying to have users select multiple options from a dropdown list. But before each selection, I would like to have a message appear on the screen asking if the user if they would like to select another option - Yes or No. Yes or No would be required fields. If the user select Yes, they can select another option from the drop down list (displaying all selected options on the screen before processing). If the user select No, they can proceed to the next fields. I have to searched the Internet for days, but was unable to locate anything close. If possible I would like to implement the amselect.js code into this difficult task. Can you guys please assist or point me in the right direction? I want to write a conditional statement like the following: if ($value = "300x") { however, I want this to work if x is changed to anything. So the conditional should work if the following is true: if ($value = "300dog") { or if ($value = "300cat") { How do I make it work as long as 300 is present regardless of what follows after. Thanks in advance! Hey, been banging my head against the wall for a couple of hours now. There is an If () in the code that is driving me crazy because it is not behaving like I expect it to.. foreach ( $types as $type ) { if ( !isset( $type->modclass ) or !isset( $type->typestr ) ) { debugging( 'Incorrect activity type in ' . $modname ); continue; } $var = (string)$type->type; if ( $var != 'assignment&type=online' ) { print '<br/>' . $var . '<br/>'; if ( $type->modclass == MOD_CLASS_RESOURCE ) { $resources[$type->type] = $type->typestr; } else { $activities[$type->type] = $type->typestr; } } } results in... Code: [Select] label resource&type=text resource&type=html resource&type=file resource&type=directory resource&type=ims assignment_group_start assignment&type=upload assignment&type=online assignment&type=uploadsingle assignment&type=offline assignment_group_end Notice the assignment&type=online in the output... I'm just about ready to give up as to why it is still outputting $var when it is clearly equal to the compared string? Any ideas? Hello, this is my first PHP project, and I am having issues getting it to correctly display an error ONLY if the input is an error It displays the error upon first load of the page w/o pressing submit. How would I use Code: [Select] isset($_POST['submit'])to fix it? Code: [Select] <?php $inputid = $_POST['steamid']; $steam_prefix = substr($inputid, 0, 10); $prefix_length = 10; $char_total = strlen($inputid); $steam_suffixchars = ($char_total - $prefix_length); $suffix_check = substr($inputid, 10, $steam_suffixchars); $class_set = "notranslate"; $is_submit = isset($_POST['submit']); if(is_numeric($suffix_check) == true) $suffix_valid = true; elseif(is_int($suffix_check) == false) $suffix_valid = false; if($char_total > 25 || $char_total < 11) $char_valid = false; else $char_valid = true; if($steam_prefix === "STEAM_0:1:" || $steam_prefix === "STEAM_0:0:") $prefix_check = true; elseif($steam_prefix != "STEAM_0:1:" || $steam_prefix != "STEAM_0:0:") $prefix_check = false; if (preg_match('/^[A-Z0-9-:-_-]+$/', $inputid)) $chars_matched = true; else $chars_matched = false; if($suffix_check == true && $prefix_check == true && $char_valid == true && $chars_matched == true) echo "Approved!"; elseif(isset($_POST['anon'])) echo "Approved!"; else echo "error!"; ?> I have the following code which seems to be in error in the conditional statement. The queries to the database produce the expected results, and the echo statements work OK. I want to make a selection based on whether data exists in the database for passState when passState=1. Can anyone tell me what is wrong with the conditional statement? Code: [Select] <?php $query1 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' AND passState = 1 ORDER BY quizTitle ASC, passState DESC, userDate DESC "); $query2 = mysql_query("SELECT DISTINCT quizTitle, userId, passState, userScore, totalScore, DATE_FORMAT(userDate,'%b %e, %Y') AS userDate FROM quiz WHERE managerId = '$managerId' AND userId = '$userId' AND passState = 0 ORDER BY quizTitle ASC, passState DESC, userDate DESC "); ?> <table width="778" style="font-size:16px"> <tr> <?php if ($query1) { while ($row1 = mysql_fetch_array($query1)) { echo'<td width="13"></td> <td width="137" style="vertical-align:middle; text-align:left;">' ?> <?php echo "{$row1['quizTitle']} <br />\n"; ?> <?php echo '</td> <td width="13"></td> <td width="132" style="vertical-align:middle; text-align:left;;">' ?> <?php echo "{$row1['userDate']} <br />\n"; ?> <?php echo '</td> <td width="22"></td> <td width="112" style="text-align:center; text-align:center;">' ?> <?php if ("{$row1['passState']}" == 1) {echo "<img src=' ../wood/wood_tool_images/tick2.png' /><br />\n";}?> <?php echo '</td> <td width="30"></td> <td width="103" style="text-align:center; text-align:center;">' ?> <?php if ("{$row1['passState']}" == 0) {echo "<img src=' ../wood/wood_tool_images/cross2.png' /><br />\n";} ?> <?php echo '</td> <td width="19"></td> <td width="126" style="vertical-align:middle; text-align:center;">' ?> <?php echo "{$row1['userScore']}".'/'."{$row1['totalScore']} <br />\n"; ?> <?php echo '</td> <td width="23"></td> </tr>'; } }else{ while ($row2 = mysql_fetch_array($query2)) { echo '<td width="13"></td> <td width="137" style="vertical-align:middle; text-align:left;">' ?> <?php echo "{$row2['quizTitle']} <br />\n"; ?> <?php echo '</td> <td width="13"></td> <td width="132" style="vertical-align:middle; text-align:left;;">' ?> <?php echo "{$row2['userDate']} <br />\n"; ?> <?php echo '</td> <td width="22"></td> <td width="112" style="text-align:center; text-align:center;">' ?> <?php if ("{$row2['passState']}" == 1) {echo "<img src=' ../wood/wood_tool_images/tick2.png' /><br />\n";}?> <?php echo '</td> <td width="30"></td> <td width="103" style="text-align:center; text-align:center;">' ?> <?php if ("{$row2['passState']}" == 0) {echo "<img src=' ../wood/wood_tool_images/cross2.png' /><br />\n";} ?> <?php echo '</td> <td width="19"></td> <td width="126" style="vertical-align:middle; text-align:center;">' ?> <?php echo "{$row2['userScore']}".'/'."{$row2['totalScore']} <br />\n"; ?> <?php echo '</td> <td width="23"></td> </tr>'; } } ?> </table> I am trying to identify the username from a series of windows logs. I have been using (?:User Name:|Account Name:)\s*([\S]+) and it works for examples 1-4, however I'm having problems with example 5. Because it has two occurrences of the pattern Account Name: in the string I can only get the regex to return the first match, i.e. USER-PC$. How can I tell regex, that if there are two Account Name: patterns in the string, or the string contains the pattern "New Logon:" then return the second Account Name: match, i.e. John.Doe? eg 1 - The screen saver was invoked. Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4091 Session ID: 1 eg 2 - User initiated logoff: Subject: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0x3d95c This event is generated when a logoff is initiated. No further user-initiated activity can occur. This event can be interpreted as a logoff event. eg 3 - User Logoff: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x458E4AB4) Logon Type: 8 eg 4 - Successful Network Logon: User Name: John.Doe Domain: INTERNAL Logon ID: (0x0,0x43) Logon Type: 8 Logon Process: Advapi Authentication Package: Negotiate Workstation Name: USER-PC Logon GUID: {2e483a4f-} Caller User Name: USER-PC $ Caller Domain: INTERNAL Caller Logon ID: (0x0,0x7) Caller Process ID: 4816 Transited Services: - Source Network Address: xx.xxx.xx.x Source Port: 35029 eg 5 - An account was successfully logged on. Subject: Security ID: S-X-X Account Name: USER-PC$ Account Domain: INTERNAL Logon ID: 0x3e7 Logon Type: 2 New Logon: Security ID: S-X-X Account Name: John.Doe Account Domain: INTERNAL Logon ID: 0xa4062 Logon GUID: {23-xx-22} Process Information: Process ID: 0x2fc Process Name: C:\Windows\System32\winlogon.exe Network Information: Workstation Name: USER-PC Source Network Address: xx.x.x.x Source Port: 0 Any help would be appreciated:) is it possible to have a script that changes header based on what page the user came from. something like Code: [Select] if ($_SERVER['HTTP_REFERER']) == http://www.site.com/pagebefore.php) { // do nothing, letting page generate } else { header("Location: back_to_the_start_buddy.php"); } This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=318784.0 I've got a dev server which, for reasons I won't go into, needs to have different .htaccess files for each site (and subfolders within them) within it. But not always. What I need to do is: - For the folder I put the PHP script in, and every folder under it (the whole tree under it): - If there's a .htaccess file an no .htaccess.dev file, copy .htaccess and name the copy .htaccess.dev (and look in subfolders) If there's a .htaccess file and also a .htaccess.dev file, do nothing (but keep looking for subfolders) If there's neither a .htaccess or .htaccess.dev file, do nothing (but keep looking for subfolders)I'd try to come up with something myself, but getting it wrong will be fairly catastrophic! I'm sure the conditional copy / rename bit is relatively straightforward, but it's the recursive searching of the whole file-system under the script's location that I'm not sure about... Any help greatly appreciated, as always! I have SSH access, if it's easier done that way maybe I'm approaching it wrong?
Hi everyone, I'm trying to create a site where teachers can upload educational animations (swfs) and source files (.fla's) to a site as a shared resource for others to use in their classrooms. I've concatinated a random number to both the source file and animation file to circumvent the problem of files with same names being uploaded. However, I have one small problem. The source file is not a mandatory upload, so sometimes the $source_file is null. However, with the random number concatinated, $source_fileX is not null. I tried to write some code saying that if $source_file is null, then $source_fileX should be null, else $source_fileX should be random_number concatinated with $source_file , but it doesn't seem to be working. The animation files are uploading fine. It's just the source files that are not. Nor is $source_fileX being inserted into the source_file field in the database. Code below. Thanks in advance. Code: [Select] <?php $keywords = $_POST["keywords"]; $subject = $_POST["subject"]; $description = $_POST["description"]; $website = $_POST["website"]; $firstname = $_POST["firstname"]; $lastname = $_POST["lastname"]; $school = $_POST["school"]; $animation_file = $_POST["animation_file"]; $source_file = $_POST["source_file"]; $random_digit=rand(00000, 9999); $animation_fileX=$random_digit . $_FILES['animation_file']['name']; if($animation_fileX!="") { if (!copy($_FILES['animation_file']['tmp_name'], "uploads/$animation_fileX")) { echo "failed to copy \n"; } } if ($source_file!="") { $source_fileX=$random_digit . $_FILES['source_file']['name']; } else { $source_fileX=""; } if($source_fileX!="") { if (!copy($_FILES['source_file']['tmp_name'], "source_file_uploads/$source_fileX")) { echo "failed to copy \n"; } } //**********************SEND TO DATABASE**************************** include 'mysql_connect.php'; $query = "INSERT INTO animation_uploads (date, animation_file, source_file, keywords, subject, description, firstname, lastname, school, website)" . "VALUES (NOW(), '$animation_fileX', '$source_fileX', '$keywords', '$subject' , '$description', '$firstname', '$lastname', '$school' , '$website')"; //if($query){echo 'data has been placed'} mysql_query($query) or die(mysql_error()); //***********************END OF DATABASE CODE*********************** Hi, Why doesn't this work? Driving me nuts! Thanks. <?php if($_SERVER[PHP_SELF] == 'somepage.php') { Header("Location: http://www.thissite.com"); } else { Header("Location: http://www.anothersite.com"); } ?> The code NEVER redirects to the first URL (thissite.com). It ALWAYS redirects to the second URL (anothersite.com). What the heck am I doing wrong? Hi,
I have the 'onbeforeunload' event set on the 'body' tag to set a JS function to trigger ONLY if a conditionis set - two var's equaling one another. Note: that all works just fine - no issues with the default setup.
However, This function should NOT trigger the event if the 'submit' button is click (therefore suppressing the 'process()' function set on 'body' tag. Reason: that means staff completed the transaction and data actually saved to the database. The 'cancel.html' required to inform them their action canceled the process and no record created as a result.
----
Here's what i have thus far - appreciate some insight to get this final piece to work ('process' function should NOT fire when 'submit' button click which triggers 'checkfire' function). That's my problem - not able to pass local var out of 'checkfire' function to update global var which then read by 'process' function. (Brain dead!)
=====
Here's the code for review:
* This is the snippet that sets the default var values and the 'checkfire' function that will be called from the 'submit' button
<script type="text/javascript"> var viewer = "fire"; var jscheck = viewer; // if function called, then update var jscheck function checkFire() { jscheck = "nofire"; alert("jscheck value is now: " + jscheck); return jscheck; } </script>* Here's the part that fires the 'cancel.html' page if staff member clicks away from the page without submitting the form data. This is where we need to display the cancelation policy advising they did not complete the process by submitting info. <script type="text/javascript"> // Process to advise member by leaving page without clicking "Submit Record" button, canceled the entire process / update if (viewer == jscheck) { function process() { window.open('http://www.domain/canceled.html', '_blank'); self.blur(); } } </script>and finally, the Body tag showing 'process()' function and the 'submit' button showing onclick event calling 'checkfire()' func. <body onbeforeunload="process()"> <input name="sumbit" value="Submit Record" onclick="checkFire();" />Again, If the 'submit' button is clicked, then the 'process()' should NOT trigger at that point. ISSUE: this is what's happening - process() function firing even when the form submitted (it should ONLY fire if staff leaves the page prior to submitting the form which is requirement to close out work order). ---- I'm not sure how to dynamically 'remove' the onbeforeunload event off the 'body' tag or pass the 'checkfire()' value of 'jscheck' out of that function to global jscheck var to cause the conditional logic in 'process()' to fail - resulting in no action. Any help with this appreciated - thx! Edited by n1concepts, 23 September 2014 - 02:15 PM. Hi, I've been playing around with inserting the name of a file ($additional_upload_nameX) into the database only if it has been uploaded (it's not mandatory). When I submit the form, I'm told I have a problem with my WHERE clause. Any idea what I'm doing wrong here? Code: [Select] $query2 = "INSERT INTO uploads (date, upload_name, topic, year, status, keywords, description )" . "VALUES (NOW(), '$additional_upload_nameX', '$topic', '$year', '$status', '$keywords' , '$description') WHERE $additional_upload_nameX != ''"; //if($query){echo 'data has been placed'} mysql_query($query2) or die(mysql_error()); |