PHP - How To Make A Long If..elseif String Shorter
Similar TutorialsHi, I'm getting this error: Warning: mktime() expects parameter 5 to be long, string given in /home/user/public_html/include/functions.php on line 58 The code is: if($Date_Format == 1) #For dd-mm-yyyy { $Date_Output = date("d-m-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 2) #For dd/mm/yyyy { $Date_Output = date("d/m/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 3) #For mm-dd-yyyy { $Date_Output = date("m-d-Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 4) #For mm/dd/yyyy { $Date_Output = date("m/d/Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 5) #For Mon Day YYYY { $Date_Output = date("M D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 6) #For Month Day YYYY { $Date_Output = date("F D Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 7) #For Date"nd" Month YYYY { $Date_Output = date("d\\t\h F Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 8) #For Month Day YYYY { $Date_Output = date("F d Y",mktime(0,0,0,$Month,$Day,$Year)); } elseif($Date_Format == 9) #For Month Day YYYY { $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); // Line 58 } return $Date_Output; } else { return NULL; Line 58 says $Date_Output = date("d/m/Y H:i",mktime($DateDispsplittimehr,$DateDispsplittimemin,0,$Month,$Day,$Year)); I really appreciate any help on this. hi there - hello dear PHP-Friends, good evening! - i want to extract some data ouf of a large html-file. i have - a very very large amount of data: approx 5000 x the following line-sheme!: Quote 67003 Cato Bontjes Vice Versum House 1 28832 Achim 62042 Cato Bontjes Vice Versum House 2 28832 Achim 41798 Cato Bontjes Vice Versum House 3 37139 Adelebsen 40034 Cato Bontjes Vice Versum House 4 21365 Adendorf 46218 Cato Bontjes Vice Versum House 5 31855 Aerzen 42481Cato Bontjes Vice Versum House 6 21702 Ahlerstedt 49761 Cato Bontjes Vice Versum House 7 26197 Ahlhorn Question: how can i extract the first 5 first digits...!? I have allready some solutions here - i need a very very robuste solution diblertone1 Here is the error: Code: [Select] Warning: image_type_to_extension() expects parameter 1 to be long, string given in C:\wamp\www\Login\inc\edit-profile.php on line 23 Here is the code for line 23: Code: [Select] $type = image_type_to_extension($_FILES['pic']['type'], true); Here is the code for the whole page: Code: [Select] <?php if(!$userb) { login('?p=edit-profile'); die(); } if(isset($_POST['submit'])) { $mottof = mysql_real_escape_string(bb($_POST['motto'])); $aboutf = mysql_real_escape_string(bb($_POST['about'])); $interesrsf = mysql_real_escape_string(bb($_POST['interests'])); $booksf = mysql_real_escape_string(bb($_POST['books'])); $authorsf = mysql_real_escape_string(bb($_POST['author'])); $randf = mysql_real_escape_string(bb($_POST['random'])); if($_FILES['pic']['type'] == 'image/gif' || $_FILES['pic']['type'] == 'image/jpeg' || $_FILES['pic']['type'] =-'image/pjpeg' || $_FILES['pic']['type'] == 'image/png') { if($_FILES['pic']['size'] < 8388608) { if($_FILES['pic']['name'] != '') { //mkdir('/images/user_images/' .$user_log); $type = image_type_to_extension($_FILES['pic']['type'], true); move_uploaded_file($_FILES['pic']['tmp_name'], 'images/user_images/' .$user_log .'pp' .$type); $path = 'images/user_images/' .$user_log .'pp' .$type; } else { $path = 'images/user_images/user.jpg';} } $q2 = "UPDATE login_info SET profile_picture = '$path' WHERE user='$user_log' "; mysql_query($q2) or die(mysql_error()); } $query = " UPDATE login_info SET motto = '$mottof', about = '$aboutf', fav_books = '$booksf', fav_authors = '$authorsf', interests = '$interesrsf', random = '$randf' WHERE user='$user_log' "; mysql_query($query); echo '<h3> Profile Updated </h3>'; } $q = "SELECT * FROM login_info WHERE user='$user_log' "; $s = mysql_query($q) or die(mysql_error()); $r = mysql_fetch_assoc($s); $motto = $r['motto']; $about = $r['about']; $books= $r['fav_books']; $authors = $r['fav_authors']; $rand = $r['random']; $interests = $r['Interests']; if(isset($_GET['act'])){$red = '?p=' .$rpage ;} else {$red='?p=edit_profile';} echo" <form action='?p=edit-profile' enctype='multipart/form-data' method='post' > <label>Motto: </label> <input type='text' name='motto' value='$motto' placeholder='Motto' /> <label> About :</label> <textarea name='about' cols='40' rows='10'> $about</textarea> <label> Interests: </label> <textarea name='interests' cols='40' rows='10'> $interests </textarea> <label> Favorite Books: </label> <textarea name='books' cols='40' rows='10'> $books </textarea> <label> Favorite Authors </label> <textarea name='author' cols='40' rows='10'> $authors </textarea> <label> Random: </label> <textarea name='random' cols='40' rows='10'> $rand </textarea> "; ?> <script type='text/javascript'> function if_checked() { if($('#cur').is(':checked')) { $('#pic').attr('disabled', true); } else { $('#pic').removeAttr('disabled'); } } </script> <label> Profile Pictu </label> <input type='checkbox' name= 'current' id='cur' onchange="if_checked();" checked /> <label for='current' style='display:inline;'> Current profile picture </label> <br /> <input type='file' id='pic' name='pic' disabled="disabled" /> <br /> <input type='submit' value ='Submit' name='submit' /> </form> Ive used the function before and I havent encountered this error. Im not sure what it means. Hi folks, just wondering if there is a quicker, shorter way of coding this: Code: [Select] <p>Which of the following best describes your religion:<br> <select name="religious"> <option <?php if ($religious == 0) {echo 'selected="selected"';} ?> value="0">Non religious</option> <option <?php if ($religious == 1) {echo 'selected="selected"';} ?> value="1">Christianity</option> <option <?php if ($religious == 2) {echo 'selected="selected"';} ?> value="2">Hinduism</option> <option <?php if ($religious == 3) {echo 'selected="selected"';} ?> value="3">Buddhism</option> <option <?php if ($religious == 4) {echo 'selected="selected"';} ?> value="4">Chinese traditional religion</option> <option <?php if ($religious == 5) {echo 'selected="selected"';} ?> value="5">Judaism</option> <option <?php if ($religious == 6) {echo 'selected="selected"';} ?> value="6">Atheist</option> <option <?php if ($religious == 7) {echo 'selected="selected"';} ?> value="7">Other</option> </select></p> I have a page with a load of options and to go through all of these is making the code huge. Any quicker ways? I have such lines of code: $link["beF1LP"]="https://www.site.com"; $link["beN1LP"]="https://www.site.com"; I know I can simplify it like this: $link["beF1LP"]=$link["beN1LP"]="https://www.site.com"; But I wanted something like this: $link["be(F|N)1LP"]="https://www.site.com"; Which did not work. How do I get it working for the string inside the brackets and under the quotes while using OR and/or other operators?
Thank you ok I need to know how to do this say I have variables.. like so $a[] = 12345; $a[] = 23456; $a[] = 35424; what do I have to do to get those variables to combine the value? and make that a variable? so it would be like $aCompiled = 12345,23456,35424, puts them in a string then I can use the variable later on in the script.. 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 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 } ?> 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 />'; 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? 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 ---"; } ?> Hi 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, 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 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. 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'); } } } ?> 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!! 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? 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>"; } 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."); } ?> |