PHP - If A Or B Do This Elseif C Do Something Else
it should be pretty simple. if member type == Gold or silver echo from a
if $member== client echo form b. the query is working as i can echo out $member and display the member type before the if statement. after the if statement no variables will echo out. Gold is with a capital G and silver is not in the database. Code: [Select] $data=mysql_query(" SELECT * FROM members WHERE email='$myusername' and password='$mypassword'")or die (mysql_error()); while ($info=mysql_fetch_array($data)){ $member=$info['member_type']; $email=$info['email']; $frist=$info['fname']; $last=$info['lname']; $country=$info['country']; $add=$info['address']; $state=$info['state']; $zip=$info['zip']; } echo $member; echo $frist; ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>3designbreif.com | Create profile</title> <link rel="stylesheet" type="text/css" href="../css/3lance.css" media="all" /> </head> <body> <div class="content" style="background-image:url(../img/3lancecreatep.png);"> <div id="update"> <?php echo "welcome ".$email." Please Change your password and comfirm details."; echo "<br/>"; ?> <?php if($member=='Gold' || $member=='silver'){ ?> <form action="../php/update.php" method="post"> <div style="clear:both;"></div> <label for='password'>Password</label><input type="password" name="password" /> <div style="clear:both;"></div> <label for='password2'>Comfirm Password</label><input type="password" name="password2" /> <div style="clear:both;"></div> <label for="name">Name</label><input type="text" name="name" value="<?php $frist?>"/> <div style="clear:both;"></div> <label for="lname">Last Name</label><input type="text" name="lname" value="<?php $last?>" /> <div style="clear:both;"></div> <label for="address">Address</label><input type="text" name="address" value="<?php $add?>" /> <div style="clear:both;"></div> <label for="state">State</label><input type="text" name="state" value="<?php $state?>" /> <div style="clear:both;"></div> <label for="country">Country</label><input type="text" name="country" value="<?php $country?>" /> <div style="clear:both;"></div> <label for="zip">Zip</label><input type="text" name="zip"value="<?php $zip?>" /> <div style="clear:both;"></div> <?php } if($member=='client'){ echo $member; ?> <form action="../php/update2.php" method="post"> <div style="clear:both;"></div> <label for="password">Password</label><input type="password" name="password" /> <div style="clear:both;"></div> <label for="password2">Comfirm Password</label><input type="password" name="password2" /> <div style="clear:both;"></div> <label for="name">Name</label><input type="text" name="name" value="<?php echo $frist;?>" /> <div style="clear:both;"></div> <label for="lname">Last Name</label><input type="text" name="lname" value="<?php echo $last;?>" /> <div style="clear:both;"></div> <label for="address">Address</label><input type="text" name="address" value="<?php echo $add;?>" /> <div style="clear:both;"></div> <label for="state">State</label><input type="text" name="state" value="<?php echo $state;?>" /> <div style="clear:both;"></div> <label for="country">Country</label><input type="text" name="country" value="<?php echo $country;?>" /> <div style="clear:both;"></div> <label for="zip">Zip</label><input type="text" name="zip"value="<?php echo $zip;?>" /> <div style="clear:both;"></div> <?php } ?> Similar TutorialsHi Guys, I'm not sure what to do here. I have a variable that is passed on via a url. I have a database table that has a field called 'publish'. This field contains either a Yes or a No. All I want to do is check the field an if it is Yes then make it No, and likewise if it is No then make it Yes. Here is my code. It changes one way but not the other. The value of $publish seems to stay the same...please help...Thank you. Code: [Select] <?php // connect to the database include('connect-db.php'); // get id value $id = $_GET['id']; echo "$id"; $publish = $_GET['publish']; echo "$publish"; $sql="SELECT * FROM events WHERE ID='$id'"; $result=mysql_query($sql); if ($publish='Yes') { $publish=='No'; } else { $publish=='Yes'; } // echo "<p>$publish</p>"; $sqltwo = "UPDATE events SET publish='$publish' WHERE ID='$id'"; $resulttwo = mysql_query($sqltwo); // sleep(2); // header("Location: beacon.php"); ?> hi everybody, every time i asked a question here, i got quick and perfect answers. now i am back again with one i have a simple form which updates some fields in a mysql table. everything works fine, am just trying to convert numbers posted through the form into words on the update page and it is not working for example: the form sends score to the update page, it is either 1, 2 or 3 all i want is that if the score on the form page was 1 then it should update the field in the table with the value "Low" if 2 then "Average" if 3 then "High" the reason is that i dont want the user to select 1,2 or 3 and also low, average and high. so i can simply recieve 1,2 or 3 and update 2 fields at the same time. i tried it with elseif, it doesn't work my code is as follows: <? if($_POST['Submit']){ $host="mysql"; $db_user="me"; $db_password="mypassword"; $database="mydb"; mysql_connect($host,$db_user,$db_password); mysql_select_db($database); $result=mysql_query("SELECT id FROM mytable ORDER BY id ASC"); while($row=mysql_fetch_assoc($result)){ $name=$_POST["name_".$row[id]]; $lastname=$_POST["lastname_".$row[id]]; $email=$_POST["email_".$row[id]]; $score=$_POST["score_".$row[id]]; // this is where i don't simply want to update the record // with the $_POST, rather convert the number into aplhabets, i.e. 1=Low, 2=Average and 3=High mysql_query("UPDATE mytable SET name='$name', lastname='$lastname', email='$email', score='$score' where id='$row[id]'"); } echo "--- Update Complete ---"; } ?> the following is the contents of my index.php file if (isset($_GET['topic'])) { include 'modules/pages/posts.php'; } elseif (isset($_GET['forum'])) { include 'modules/pages/topics.php'; } elseif (isset($_GET['parent'])) { include 'modules/pages/parents.php'; } elseif (isset($_GET['do']) == 'unanswered') { include 'modules/pages/unanswered.php'; } elseif (isset($_GET['do']) == 'today') { include 'modules/pages/today.php'; } else { include 'modules/pages/forums.php'; } as you can see depending on what the get value is it loads a corrosponding page. however on the last 2 statements it loads the same page index.php?do=unanswered. why wont it load index.php?do=today when the $_GET value == today? I am a novice and had this code below working fine until I added the If / elseif to "plan_id". Prior, the column would just list out the numbers from the database, but I want the numbers to echo out the text. Any help is appreciated. while($row = mysql_fetch_array($result)){ $bg = ($bg=='#ffffff' ? '#e7e8e8' : '#ffffff'); //For Alternate Row Colors echo '<tr bgcolor="' . $bg . '"><td>' . $row['customers_firstname'] . " " . $row['customers_lastname'] . '</td><td>' . date("M. d, Y", strtotime($row['date'])) . '</td><td>' . if ($row['plan_id'] == 1) { echo "1 DVD"; } elseif ($row['plan_id'] == 2) { echo "2 DVDs"; } else { echo "3 DVDs"; } . '</td></tr>';} echo '</table>'; echo '<br />'; Hi, I can't see for looking on quite simply a very easy statement; Code: [Select] $cartTotal = '900'; echo 'cart total '.$cartTotal.'<br/>'; $postage = '100'; echo 'Postage '.$postage.'<br/>'; $postThreshold = '85'; echo 'Post Threshold '.$postThreshold.'<br/>'; if ($cartTotal <= $postThreshold) { echo 'too little'; } elseif (($cartTotal >= $postThreshold) || ($cartTotal <= $postage)) { echo 'difference'; } else { echo 'over a ton'; }It works apart from if the cart total is above 100. What have I missed? Thanks is there a better way of coding this using arrays? ive never had a use for them b4 the if and the else statment is ok but its the elseif that i think i can put into an array ut what i tryed didnt work. what id like to do Code: [Select] $loc = array('HDD', 'APRIL 2011', 'WHITE VISTA', 'NEW 1.5 TB', 'UNVALIDATED') elseif($rows['auth'] == 'YES' and $rows['location'] == $loc){ $bgc = "wait" ; what works Code: [Select] if ($rows['auth'] == 'YES' and $rows['location'] == 'SERVER'){ $bgc = "pass" ; } elseif($rows['auth'] == 'YES' and $rows['location'] == 'HDD'){ $bgc = "wait" ; }elseif($rows['auth'] == 'YES' and $rows['location'] == 'APRIL 2011'){ $bgc = "wait" ; }elseif($rows['auth'] == 'YES' and $rows['location'] == 'WHITE VISTA'){ $bgc = "wait" ; }elseif($rows['auth'] == 'YES' and $rows['location'] == 'NEW 1.5 TB'){ $bgc = "wait" ; }elseif($rows['auth'] == 'YES' and $rows['location'] == 'UNVALIDATED'){ $bgc = "wait" ; }else{ $bgc = "fail"; } thanks i'm having trouble with an elseif statement. its not displaying the result it should ?php if(isset($_COOKIE['ID_forum'])){ $username = $_COOKIE['ID_forum']; $query = "SELECT * FROM users WHERE username = '".$username."'"; $level = mysql_query($query) or die ("Select Error :" . mysql_error()); $userlevel = $level['user_level']; echo $userlevel; if ($userlevel == "1") { echo 'you are a member'; } elseif ($userlevel == "2") { echo 'you are a moderator'; } elseif ($userlevel == "3") { echo 'you are an administrator '; } else echo'you are not logged in'; } ?> it is echoing out 'you are not logged in', when it should be saying 'you are an administrator', as the value in the table is 3. i do know that the cookie 'ID_forum' is there, but i cant find why its not working properly. Any ideas would be great. Thanks Okay, I have a script that if someone is a particular "class", they can't get additional bonus points for their character. However, if they aren't that class, then they get additional points. But, it seems to be ignoring the elseif and gives a strength point no matter what the class is. I don't see where I coded wrong, so I would appreciate any help! Thanks! if ($expgain + $player->mine_exp >= $player->mine_maxexp) { echo "<br /><b>Your mining leveled up!</b>"; echo "$blurb $randeffect<p>"; if(($strength + $agility + $wisdom + $vitality >=100) && ($class != 'Apprentice' || $class != 'Mage' || $class != 'Priest' || $class != 'Rogue' || $class != 'Scholar' || $class != 'Wanderer' || $class != 'Warrior' || $class != 'Woodsman')) { echo "<br /><b>You gained 1 strength point!</b>"; $query = $db->execute("update `users` set `energy`=?, `mine_level`=?, `mine_exp`=?, `minecount`=?, `strength`=?, `mine_maxexp`=? where `id`=?", array($player->energy - 1, $player->mine_level + 1, $player->mine_exp + 1, $player->minecount + 1, $player->strength + 1, $player->mine_maxexp + $newmax, $player->id)); } elseif (($strength + $agility + $wisdom + $vitality >= 100) && ($class = 'Apprentice' || $class = 'Mage' || $class = 'Priest' || $class = 'Rogue' || $class = 'Scholar' || $class = 'Wanderer' || $class = 'Warrior' || $class = 'Woodsman')) { echo "You have already maxed out your stats at 100!"; $query = $db->execute("update `users` set `energy`=?, `mine_level`=?, `mine_exp`=?, `minecount`=?, `mine_maxexp`=? where `id`=?", array($player->energy - 1, $player->mine_level + 1, $player->mine_exp + 1, $player->minecount + 1, $player->mine_maxexp + $newmax, $player->id)); } elseif($strength + $vitality + $wisdom + $agility < 100) { echo "<br /><b>Your mining leveled up and you gained 1 strength point!</b>"; $query = $db->execute("update `users` set `energy`=?, `mine_level`=?, `mine_exp`=?, `minecount`=?, `strength`=?, `mine_maxexp`=? where `id`=?", array($player->energy - 1, $player->mine_level + 1, $player->mine_exp + 1, $player->minecount + 1, $player->strength + 1, $player->mine_maxexp + $newmax, $player->id)); } } else { $query = $db->execute("update `users` set `energy`=?, `mine_exp`=?, `minecount`=? where `id`=?", array($player->energy - 1, $player->mine_exp + 1, $player->minecount + 1, $player->id)); echo "$blurb $randeffect<p>"; } Hi Guys, Beginner needs help with accommodation search feature...i have two drop downs(area and type), each one has an 'any' option. I cant evalute the 'any' options directly against the database so have written this: Code: [Select] <?php //query database if ($_SESSION['type']== 'any' && $_SESSION['area']== 'any'){ $query = mysql_query("SELECT * FROM hotels Order by RAND() "); } elseif ($_SESSION['area'] == 'any' && $_SESSION['type'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE type = $_SESSION[type] Order by RAND()"); } elseif ($_SESSION['type'] == 'any' && $_SESSION['area'] != 'any'){ $query = mysql_query("SELECT * FROM hotels WHERE location =$_SESSION[area] Order by RAND()"); } else{ $query = mysql_query("SELECT * FROM hotels WHERE location ='$_SESSION[area]' AND type ='$_SESSION[type]' Order by RAND()"); } //show results while ($search_result = mysql_fetch_assoc($query)) { echo '<b>'.$search_result[name] . '</b><br>'; echo '<p><img src="'.$search_result['photo1'].'" /></p>'; echo '<p><img src="'.$search_result['award'].'" /></p>'; echo $search_result[description] . '<br><br>'; }?> The first if and last else return the correct info from database but the middle two elseif's throw this error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given.... I have commented out the queries and replaced them with simple echoes and they all seem to evaluate correctly!. So im lost why $query isnt assigned in the middle two elseif's ?? Any ideas what im doing wrong and is there a better way. Cheers!! The below code should take you to a different page depending on what you choice in the drop down, but all the results only take you to the first on even when you put a different option in the drop down, any ideas? Code: [Select] <?php ob_start(); session_start(); $pagerank=1; if ($rank < $pagerank){ header('Location:main.php?id=lowrank.php'); } else{ ?> <form action="main.php?id=search.php" method="post"> <table width="725" border="0" cellspacing="1" cellpadding="1"> <tr> <td width="228">Name: <input name="name" type="text" /></td> <td width="490"><select name="type"> <option>All</option> <option>Alliance</option> <option>Corporation</option> <option>Pilot Name</option> <option>Ship Name</option> <option>Ship Type</option> <option>System Name</option> <option>System Type</option> </select></td> </tr> <tr> <td></td> <td><input name="Submit" type="Submit" /></td> </tr> </table> </form> <?php if (isset($_POST['Submit'])) { $name = $_POST['name']; $type = $_POST['type']; if ($type = "System Name" OR "System Type") { header('Location:main.php?id=searchsystem.php'); exit; } Elseif ($type = "All") { header('Location:main.php?id=searchall.php'); exit; } Else { header('Location:main.php?id=searchpilot.php'); } } } ?> I know this works: if($Authorized == "Declined") { echo "Didn't work"; } else { echo "Success"; } ?> What if I wanted it to echo "Didn't work" if $Authorized == "Declined" OR if the string is empty, i.e. $Authorized == "" Is this it? if($Authorized == "Declined") { echo "Didn't work"; } [elseif ($Authorized == "") { echo "Still didn't work"; }] } else { echo "Success"; } ?> Thanks. I can't get these two if, elseif and else statements too work, here is the code: if(empty($this->password)){ $this->errors[] = 'You must enter a password!'; } elseif(!strlen($this->password) >= 6){ $this->errors[] = 'Your password must be longer than 6 characters!'; } if(empty($this->email)){ $this->errors[] = 'You must enter an email address!'; } elseif(!preg_match('/^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/',$this->email)){ $this->errors[] = 'Your password can only contain these characters: a-z, A-Z and 0-9!'; } if(empty($this->confemail)){ $this->errors[] = 'Please confirm your email address!'; } elseif(!$this->confemail == $this->email){ $this->errors[] = 'The email addresses you entered did not match!'; } The if and elseif statements for "email" work just fine but the other 2 doesn't. With the "password" i first want to check if the field is empty, and when it is, it works as it should. But when i for example type "test" too check if the password is longer than 6 characters i don't get any message at all? With the "confemail" i want to first check if the field is empty, and when it is, it works as it should. But when i type in "test@test.com" in both fields to try to compare "confemail" to "email" i still get the "Please confirm your email address!" message? Hiya, Trying to get this working based on a drop down posted from the step before. Three options are dropoff, collect and ship. This code always defaults to the first option, despite the fact that echoing the session shows the correct choice has been passed through. Here's what I have: Code: [Select] if ($_SESSION['collection'] = "dropoff") { echo "Please drop it off with us"; } elseif ($_SESSION['collection'] = "collect") { echo "Please collect it from me"; } else { echo "Please ship it to you"; } Any ideas what I'm missing here? Thanks! Is it possible to add more than one elseif in an if, elseif, else statement? Here's an example of what I'm talking about (I do realize this is not proper php syntax): Code: [Select] <?php if (name was not entered in form) { echo ("This user has not entered a name."); } elseif (email was not entered in form) { echo ("This user has not entered an email."); } elseif (age was not entered in the form) { echo ("This user has not entered their age."); } else { echo ("This user has entered all of their information."); } ?> Hello, I can't find those or mr. Google, can anyone please help me to find them? the tags that can be included in HTML and deciphered by PHP as a PHP code <if> <else> <elseif> etc.. Thanks That's right I'm pretty green when it comes to PHP. I googled it, but it looks like there are several ways to achieve this, wondering which is best.
elseif ($subcategory_id == 400)I want the code to include a number of subcategory_ids, 400, 450, 500, 760, etc. There isn't a range, so what would be the proper way to include multiple category_ids. Thank you I would like to check multiple rows from array with elseif. It's working if i add it manually, but i would like it to check all of the rows in a single elseif. Code(First if is nothing, just a example). Row is a array filled with numbers like: 3-3, 2-2 etc. Code: [Select] if("2-2" == $row["0"]){ echo BLUE; }elseif($dnumber == $row["0"]){ echo RED; }else{ echo WHITE; } PHP newb here - apologies if the answer to this is really simple.
I've tried to add a geotargetting code into my website but it appears the elseif part isn't working, no matter what I do.
Here's the code - any idea why if is fine, and else is fine, but elseif isn't?
<?php if (function_exists('showCountryContentInPage')) { if(showCountryContentInPage(array("us", "ca"),1)) { // US $region = 'USA'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } elseif(showCountryContentInPage(array("at", "es", "cy", "fi", "ee", "fr", "de", "el", "ie", "it", "mt", "lu", "lv", "nl", "pt", "sk", "si", "be"),1)) { // Europe $region = 'Europe'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } else { // UK $region = 'UK'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } ?> Hello friends, how can i combain this codes If i've 3 functions $limited,$refere,$pass all have commen result echo "good"; if($limited){ if($hits >= $limited){ echo "U1"; }else{ echo "Good"; } } else { echo "Good"; } ================================= if($refere){ if($me >= $you){ echo "U2"; }else{ echo "Good"; } } else { echo "Good"; } ================================= if($pass){ if($she >= $he){ echo "U3"; }else{ echo "Good"; } } else { echo "Good"; } thansk, it would really helps me alot Hi My PHP skills aren't that good but I know what I want to do as I have used other programming languages before. I run a WordPress website about a Church and its Cemetery. I have been researching the graves for the last 2 years and have added each grave to the website via a Custom Post Type with the buried occupants. In WordPress I have used a plugin called Advanced Custom Fields and have set each grave to allow at least 5 people buried there. So the following code below is used to check if the fields have any value which would represent each person in that grave and add it to the page. I don't know how to add it as a database table so this is the easiest way I could think of. echo '<div id="section-grave">'; echo "<h3>Who's buried in this Grave?</h3>"; //echo '<p>Listed below, are the people buried in this grave.</p>'; if(get_field('is_burial_date_known')) { // start For Loop for ($x = 1; $x <= 5; $x += 1) { $name_of_deceased = 'name_of_deceased_' . $x; $burial_date = 'burial_date_' . $x; $clergy_name = 'clergy_name_' . $x; if(get_field($name_of_deceased)) { echo '<p>' . $x . ') ' . get_field($name_of_deceased) . '</p>'; } if(get_field($burial_date)) { echo '<p>Burial Date: ' . get_field($burial_date) . '</p>'; } if(get_field($clergy_name)) { echo '<p>Buried By: ' . get_field($clergy_name) . '</p>'; echo '<hr>'; } } // end For Loop } else { echo '<p>Nobody buried here.</p>'; } echo '</div>'; I want to add a paragraph above which I have commented out to show how many people are buried in that grave. So if it was only one person then it should say 1 person as oppose to people. So I need a way of counting the names but I can't see a way how to do it. It will probably based on an IF...Elseif...Else statement and which ever condition is right it just displays the correct line or paragraph. I need a way of counting thetotal number of people per grave but outputting the total relies on the loop which is after the paragraph or line. I hope I have explained it properly so can anyone see how I can do it please? Colin |