PHP - Is_string() Not Working As I Expected
Hello I want to check that a variable the user enters is not empty and that it is a string (no numbers). Here is what i have written:
Code: [Select] <?php include('css/layout.css.php'); include('css/menu.css'); if (isset($_POST['submit'])) { include('includes/dbconn.php'); if (is_string($_POST['name']) && strlen($_POST['name']) > 0) { $name = mysql_real_escape_string($_POST['name']); } else { echo "Category name must be a word!<br />"; } if (isset($name)) { echo $name; } else { echo "something"; } } ?> and this is the form i'm getting the data from: Code: [Select] <form action="category_add.php" method="post"> <table class="table-view"> <tr> <td><label for="name">Category Name</label></td> <td><input type="text" name="name" id="name"></td> </tr> <tr> <td><input type="submit" value="Save changes" name="submit" id="submit"></td> </tr> </table> </form> If i enter nothing it works fine, if i enter a string it also works fine, the problem is when i enter 123 in the textbox, i dont get the "Category name must be a word!" as i expected i would. Could someone help me with this one please? Thanks in advance. Similar TutorialsI'm using PHP 5.2.14 under Windows XP. I'm trying to use ini_set to turn on the 'track_error' configuration option, and it's not working. I make this call, $xxx = ini_set('track_error',"1"); and it returns false. According to the documentation, track_error can be set from any source (including ini_set). What could prevent that from happening? Going back one step, I want to set track_errors so that I can fetch and process the error which occurs when mysql_connect fails. Since it fails, it returns no link, making it impossible to call mysql_errors. Whether ini_set can be made to work or not, is there another, perhaps better way to accomplish this? I am doing some study on using time() and date() and i just wrote this simple for loop to add one day to each iteration with +$i and its echoing the unix timestamp as opposed to the correctly formated date as it should be based on my code. Anyone have any idea why this is not working as expected? for($i=0; $i < 50; $i++) { echo $time = time()+$i . "<br />"; // add a day on each iteration echo date('y-m-d', $time) . "<br />"; // should echo 10-12-02, 10-12-03, 10-12-04, etc.. } what am i doing wrong here? arrgggg! maybe its too late for this s$%^#! I cannot get this INSERT to work. Not records are being added to the sys_city_dev table. No query errors are being thrown. I am simply trying to add ALL records from all_illinois to sys_city_dev and Mid should have be add as 11 in all inserts. city_name of course will be field city_name from all_illinois. Here is my code: $query = "SELECT * FROM all_illinois"; if ($results = mysqli_query($cxn, $query)) { $row_cnt = mysqli_num_rows($results); echo $row_cnt . " Total Records in Query.<br /><br />"; if (mysqli_num_rows($results)) { while ($rows = mysqli_fetch_array($results)) { echo $rows['city_name'] . "<br />"; $mid_id = '11'; $insert_city_query = "INSERT INTO sys_city_dev (ID, Mid, cityName, forder, disdplay, cid) VALUES (' ','" . $mid_id . "','" . $rows['city_name'] . "', '', '','')"; if (!$insert_city_query) exit(mysql_error()); } } } Here is my insert table structure and 5 records dump: -- -- Table structure for table `sys_city_dev` -- CREATE TABLE IF NOT EXISTS `sys_city_dev` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `Mid` int(11) NOT NULL DEFAULT '0', `cityName` varchar(30) NOT NULL DEFAULT '', `forder` int(4) NOT NULL DEFAULT '0', `disdplay` int(4) NOT NULL DEFAULT '0', `cid` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=113970 ; -- -- Dumping data for table `sys_city_dev` -- INSERT INTO `sys_city_dev` (`ID`, `Mid`, `cityName`, `forder`, `disdplay`, `cid`) VALUES (84010, 1, 'Dothan', 0, 0, 0), (84011, 1, 'Alabaster', 0, 0, 0), (84012, 1, 'Birmingham', 0, 0, 0), (84013, 2, 'Flagstaff', 0, 0, 0), (84014, 1, 'Auburn', 0, 0, 0); And the all_illinois dump w/ 5 records: -- -- Table structure for table `all_illinois` -- CREATE TABLE IF NOT EXISTS `all_illinois` ( `state_id` varchar(255) NOT NULL, `city_name` varchar(255) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `all_illinois` -- INSERT INTO `all_illinois` (`state_id`, `city_name`) VALUES ('135', 'Abingdon'), ('135', 'Adair'), ('135', 'Addieville'), ('135', 'Addison'), ('135', 'Adrian'); Hello, Currently have an array like looks like the following when using print_r($session->items): Array ( [F1225] => 1 [EDS11147317] => 1 [1156D6RE001] => 1 [I111ADE47946] => 1 [S679AQ339] => 1 [S67914599] => 1 [CH111337631254] => 1 [S6787903647] => 1 [A11144O189] => 1 [F11144520] => 1 [121584Q12] => 1 [I11144661ADE] => 1 [S678829NB] => 1 ) I am trying to check if an item is in the array and if so, display a different result but currently every item says it is in the array when they are not (unless my logic is off...from the items I am looking at some should be included and some should not..but the below code is showing every item as having the same result). Example: foreach ($items as $item) { if (in_array($item->ItemID, $session->items)) { //$session->items is the array output above echo "In Array"; } else { echo "NOT in Array"; } } Currently everything say "In Array" when some should not. Am I using the in_array incorrectly? Thanks Everyone. Good morning! I've spent hours on this to no avail. My understanding is that unset() only deletes the copy of the variable local to the current scope. But I am getting a very different result. I have the following structure and output. What am I doing wrong? <?php first_function(); second_function() { for ($count = 0; $count < $max; $count++) { $my_array = array[]; //initialize my array, local in this scope but can be called global in nested functions print_r($my_array ); //print 1: array should be always empty but is only in empty in FIRST loop. third_function(); //fills the array with numbers, see below, nested function declaring a global array print_r($my_array ); //print 3 of my_array, should be full of numbers from third_function global changes unset($my_array); //delete my array so I can start with new array in next loop print_r($my_array ); //print 4 of my_array, should be unknown variable print('End one loop'); } } third_function() { global $my_array; //declare my global variable //...fill my now global array with stuff... print_r($my_array ); //print 2: should be filled with numbers. And it is. } ?> My output amazingly looks something like this Array() Array(45,48,38...all my numbers...) Array() ERROR: Notice -- Undefined variable: my_array End one loop Array(45,48,38...all my SAME numbers again as if array was NOT unset...) ...... The first and second print lines make sense. But shouldn't the third line be the array filled with numbers generated in third_function? The fourth line error makes sense as the variable is unset. But WHAT did I unset? The next time around in the loop, the array contains the SAME numbers from the previous loop and my new numbers simply get appended to the end of the ever growing array. Why? This should not be that difficult but seems to be driving me crazy. Any help would be greatly appreciated. alexander Code: [Select] <FORM METHOD=POST ACTION=""> <p>Breeder or Business Name<br /> <input type = "text" name = "breedername" size= "25" maxlength = "50" /> </p> <p>Breeder Telephone<br /> <input type = "text" name = "breedertelephone" size= "25" maxlength = "50" /> </p> <p>Breeder Location<br /> <input type = "text" name = "breederlocation" size= "25" maxlength = "50" /> </p> <p>Breeder Desription<br /> <input type = "text" name = "breederdescription" size= "25" maxlength = "50" /> </p> <p>Leave blank<br /> <input type = "text" name = "breederverify" size= "5" maxlength = "5" /><br /><br /> </p> <input type="submit" value="Submit" name='submit' /> <br /> <br /> </form> <?php if (is_string($breederverify)) { <-- If $breederverify is set , then echo "Please leave the lowest box empty!" echo "Please leave the lowest box empty!"; } else { <-- else if $breederverify is unsigned/null execute this block. $con = mysql_connect("localhost","xxxxxxxxxx","xxxxxxxxxx"); mysql_select_db("cichlid",$con); $breedername = $_POST['breedername']; $breedertelephone = $_POST['breedertelephone']; $breederlocation = $_POST ['breederlocation']; $breederdescription = $_POST ['breederdescription']; $breederverify = $_POST ['breederverify']; $sql = "INSERT INTO breedersinfo SET breederNAME = '$breedername' , breederTELEPHONE = '$breedertelephone' , breederLOCATION = '$breederlocation' , breederDESCRIPTION = '$breederdescription'"; if(!mysql_query($sql,$con)) { die('ERROR:Could not connect ' . mysql_error ()); } echo ""; mysql_close ($con) ; } ?> All i am trying to accomplish is a form field that will only update records if the last $breederverify = $_POST ['breederverify']; is null/unasigned . I was thinking in order to do this i could use is_numeric , or is_string function to check $var ,to see what it's state is. Any help or advice would be appreciated , provided this is even possible. Cheers guys . Hello everyone, I'm working on an account update page where users can update their email address, password, or security question/answer as desired. The way I currently have it set up is so that only the information that the user enters will be updated in the database. So if they only enter a new email address, the email field in the database is updated and all other fields are left as is. I'm also trying to set a javascript even handler (onUnload) depending on whether or not anything was updated. When their info is successfully updated, I want to alert the user accordingly, as well as when no information was updated. To do this, I have a variable "$updated" that is set at "false" by default and is supposed to be set to "true" when something is updated and "none" when nothing is updated. The form and mysql commands are working and the correct fields are being updated as expected. The problem that I'm having is the $updated variable is not being set correctly and is ALWAYS being set to "true", even when it is expect to be set to "none." Here's the code that I have: Code: [Select] <?php function safe($value){ return mysql_real_escape_string($value); } $updated = "false"; if (isset($_POST['submit'])) { // If the form has been submitted. $newemail = $_POST['newemail']; $pword1 = $_POST['pword']; $question = safe($_POST['question']); $answer = safe($_POST['answer']); $updated = $_POST['updated']; $pword = md5($pword1); $q = mysql_query("SELECT * FROM `signin` WHERE email = '$newemail'") or die (mysql_error()); $r = mysql_num_rows($q); // Checks to see if anything is in the db. if ($r == 1 && $email == $newemail) { $noemail = "true"; } elseif ($r == 0) { $noemail = "true"; } else { $noemail = "false"; } if ($newemail != "" && $pword1 == "" && $question == "0") { if ($noemail == "true") { mysql_query("UPDATE `signin` SET `email` = '$newemail' WHERE email = '$email'") or die (mysql_error()); $_SESSION['email'] = $newemail; $updated = "true"; } } elseif ($newemail == "" && $pword1 != "" && $question == "0") { mysql_query("UPDATE `signin` SET `pword` = '$pword' WHERE email = '$email'") or die (mysql_error()); $updated = "true"; } elseif ($newemail == "" && $pword1 == "" && $question != "0") { mysql_query("UPDATE `signin` SET `question` = '$question',`answer` = '$answer' WHERE email = '$email'") or die (mysql_error()); $updated = "true"; } elseif ($newemail != "" && $pword1 != "" && $question == "0") { if ($noemail == "true") { mysql_query("UPDATE `signin` SET `email` = '$newemail',`pword` = '$pword' WHERE email = '$email'") or die (mysql_error()); $_SESSION['email'] = $newemail; $updated = "true"; } } elseif ($newemail != "" && $pword1 == "" && $question != "0") { if ($noemail == "true") { mysql_query("UPDATE `signin` SET `email` = '$newemail',`question` = '$question',`answer` = '$answer' WHERE email = '$email'") or die (mysql_error()); $_SESSION['email'] = $newemail; $updated = "true"; } } elseif ($newemail == "" && $pword1 != "" && $question != "0") { mysql_query("UPDATE `signin` SET `pword` = '$pword',`question` = '$question',`answer` = '$answer' WHERE email = '$email'") or die (mysql_error()); $updated = "true"; } elseif ($newemail != "" && $pword1 != "" && $question != "0") { if ($noemail == "true") { mysql_query("UPDATE `signin` SET `email` = '$newemail',`pword` = '$pword',`question` = '$question',`answer` = '$answer' WHERE email = '$email'") or die (mysql_error()); $_SESSION['email'] = $newemail; $updated = "true"; } } else { $updated == "none"; } } ?> //This is where the event handler (onUnload) is set according to what has occurred in the code above <?php if (isset($_POST['submit']) && $updated = "true") { echo "<body onUnload=\"alert('Your information has been successfully updated.')\">"; } elseif (isset($_POST['submit']) && $updated = "false") { echo "<body onUnload=\"alert('There have been no updates made to your account information.')\">"; } else { echo "<body>"; } ?> Can anyone see a problem with this and why the $updated variable is not being set as expected. Any ideas on a better way to accomplish what I want to do? Thanks in advance for anyone's help! I wish to find a way to test if multiple sites are up or not. I have been using get_headers but it seems that this does not do what I thought I would. I wish to know if the sites are down or not. Is there another function that can test what state the site is in. i.e. server not found, server issues prevented the page from showing... Using get_headers will still show the site is live even if the server is not found, due to server problems, if any. I am trying to load all rows from a table in a database into a table on a webpage. I cannot understand why the following code does not work: Code: [Select] <?php ... echo "You are currently in a fleet. The details of the fleet are below.<br>"; $fleetName = $_SESSION['charFleetName']; $sqlFleetDetails = "SELECT * FROM `$fleetName`"; $queryFleetDetails = mysql_query($sqlFleetDetails); echo "<table>"; echo "<tr>"; echo "<th>Pilot</th>"; echo "<th>Ship</th>"; echo "<th>Type</th>"; echo "</tr>"; while($rowFleetDetails = mysql_fetch_array($queryFleetDetails)) { $charId = $rowFleetDetails['charId']; $charName = $rowFleetDetails['charName']; $shipHull = $rowFleetDetails['shipHull']; $shipType = $rowFleetDetails['shipType']; echo "<tr>"; echo "<td><a href=\"#\" onClick=\"CCPEVE.showInfo{1377, " . $charId . "}>" . $charName . "</a></td>"; echo "<td>" . $shipHull . "</td>"; if($shipType == 1) echo "<td>Logistics</td>"; if($shipType == 2) echo "<td>DPS Boat</td>"; if($shipType == 3) echo "<td>Sniper 120Km+</td>"; if($shipType == 4) echo "<td>Off-grid Booster</td>"; echo "</tr>"; } echo "</table><br>"; I originally had the $rowFleetDetails['charId'] and others in the echo instead of loading them into variables then echoing the variables but changed it to see if that was working, neither is. If I add an extra line outside of the while loop to echo the output of the array then the information is displayed fine, so I know that the information is being transferred from the table into the array correctly, but why is it not outputting properly in the While loop? Hello.
I'm having some issues with a select statement containing ABS().
Here's the select query:
"SELECT gadenavn, husnr, ABS(husnr - $husnr) AS husnr_range, postnr,db, shaping, dsl_node, ctr_node, db_ctr_luftlinje, bynavn FROM `TABLE 1`, Post_numre WHERE `postnr`=`postnummer` AND `gadenavn`=`$vejnavn` AND `postnr`=`$postnr` AND `husnr`>0 ORDER BY husnr_range ASC LIMIT 5"Now lets asume my variable "$husnr" is a value of 15. In my table I have the values for coulmn "husnr": 13,12,11,10,9 What really bugs me is the outcome doing af simple "while loop" is returning the values 12,11,10,9. What happened to 13?! printing the "husnr_range" values shows "3,4,5,6". What puzzles is the row missing, as I only get 4 results, with a "LIMIT 5". Can anyone explain why the last resulst isn't included? I have a form on a page that has checkboxes for a number of entities, including one that is new. I want to determine how many checkboxes were checked for the new entity. The html is:
<div id="new" style="display:block;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['new'][]" value="EE">Excess Earnings<br /> <input type="checkbox" name="method_code['new'][]" value="DCF">Discounted Cash Flow</div> <div id="75" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /><input type="checkbox" name="method_code['75'][]" value="EE" checked="checked" >Excess Earnings<br /> <input type="checkbox" name="method_code['75'][]" value="DCF" checked="checked" >Discounted Cash Flow</div><div id="79" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['79'][]" value="EE">Excess Earnings<br /><input type="checkbox" name="method_code['79'][]" value="DCF">Discounted Cash Flow</div> <div id="77" style="display:none;">Which method(s) of valuation would you like to use for this report?<br /> <input type="checkbox" name="method_code['77'][]" value="EE">Excess Earnings<br /> <input type="checkbox" name="method_code['77'][]" value="DCF">Discounted Cash Flow</div>I looked for a method of counting the nuber of checked boxes for a given entity and found So, to count only non-empty: count(array_filter($array));here and here So I implemented that in my code and it doesn't work. I put in the following to debug: echo '<pre>'; print_r($_POST['method_code']); echo '</pre>'; echo "arraycount ".count(array_filter($_POST['method_code']['new']));die();and I get the following output: Array ( ['new'] => Array ( [0] => EE ) ['75'] => Array ( [0] => EE [1] => DCF ) ['78'] => Array ( [0] => EE ) ) arraycount 0Why is the count 0? I expect that count(array_filter($_POST['method_code']['new'])) would be one since there is one element in that array. Hello, this is my first post in this forum, in fact my first post about php. I am developing a crud application, but when i am trying to list a set of results it gives me more that the expected Let me explain. if i print_r my array (which i get it from a sql result) it gives me this Array ( => SHR1 [codprod] => SHR1 [1] => REGULAR SERVICE HOUR [proddescription] => REGULAR SERVICE HOUR [2] => 3.00 [qty] => 3.00 [3] => HR Code: [Select] => HR [4] => 45.0000 [price] => 45.0000 [5] => 0.00 [discount] => 0.00 [6] => 135.00 [amount] => 135.00 ) [/li][/list] if I foreach($detailrow as $value){ echo $detailrow['codprod'] . ", " . $detailrow['proddescription'] . ", " . $detailrow['qty'] . ", " . $detailrow['code'] . ", " . $detailrow['price'] . ", " . $detailrow['discount'] . ", " . $detailrow['amount'] . "<br/>"; } It gives me 14 rows with the same info. I run the query in mysql and it gives me only 1 result as expected. I noticed that the 14 rows are the same quantity of items in the array not results but let say columns, i dont know if it has something to do with the results. My questions: Why it is giving me 14 rows instead just one? What is the $value in the foreach function? why can't i just say foreach($myarray)? why the print_r shows me the items array duplicated using the array position and the item name? Thank you for your help!! I have only one result being displayed in a select query result whereas I'm expecting 4 results in an array. This is my code below. $sq2="SELECT course FROM course_reg WHERE userid=?"; $stm =$conn->prepare($sq2); $stm->bind_param("s",$logged); $stm->execute (); $return2= $stm->get_result(); $r2 = $return2->fetch_all(); //print_r($r2); foreach($r2 as $course){ foreach($course as $courses){ echo $courses; } }
If I do print_r($r2); it comes out with array containing all the possible results. When i loop through the array to get individual result, it only comes out with a single result. I.e CME211 I would be glad if you can help me figure where the issue is. Thanks!!!
I have an avatar upload script. The uploading and moving of the image file to the correct directory works fine, but the displaying of the image causes problems. This is the code that is supposed to display the avatar. // _DISPLAY_ avatar - START $query2 = "SELECT * FROM user WHERE user_id = '$dbuser_id'"; $row2 = mysqli_query ($dbc, $query2) or die (mysqli_error($dbc)); $assoc2 = mysqli_fetch_assoc ($row2); $target = AVATAR_UPLOADPATH; $avatar_name = $target . $assoc2['avatar']; if (is_file($assoc2['avatar'])) { echo "<img src='$avatar_name' alt='Avatar' /><br /><br />"; } else { echo "is not a regular file"; } // END The avatar column in the MySQL database says: image.jpg So there's a regular file. What I want to accomplish: I want the script to check if there's an avatar in the database, if NOT, then it should say: "no avatar uploaded yet." But as it is now it's telling me that there's no regular file even if there is, as I said the avatar column has an entry saying: image.jpg. Should I use if !empty instead? The strange thing is it used to work, now for some reason it suddenly doesn't. EDIT: With !empty it works, am I using the is_file function incorrectly? Hi all,
Wondered if anyone could assist?
On the following website the footer is not displaying as expected and cannot see why:
http://www.urxltd.com/index.php
Any other pages on the website show the footer correctly.
Thanks.
Here is my function which almost works as expected: <?php function find_value($array,$value) { for($i=1;$i<sizeof($array);$i++) { if($array[$i] == $value) { echo "$i . $array[$i]<br />"; return; } } } ?> And I call the function like so: <?php $names = array('Jason','Mike','Joe'); $name = 'Joe'; find_value($names,$name); ?> And the output is: 2 . Joe According to my understanding of Arrays, Joe would be index 3 BECAUSE my counter starts at 1 in my for loop??? Why is the result like this? What am I not understanding here? Hello guys, I devised the code block below, to retrieve all US zip codes that are located within a specified radius from the user's own zip code. So basically, the user selects a maximum distance option from a form element (not shown here)which is appended to the variable $distance. What the code below does is as follows: The longitude and latitude corresponding to the user's zip code are retrieved in the first query. Then in the second query, the longitudes and latitudes corresponding to every zip code in the database are retrieved. In the ensuing while loop, a distance calculation is made between the user's zip and every other zip using the longitudes and latitudes and if that distance falls within the selected $distance, that particular zip code is listed in a defined array called $range. Now everything works fine up to this point as tested. The problem is with the very last line. I try to implode the $range array into a string with the same name, separating the array elements with commas (,). Then when I print out the resulting string, I get the list of desired zip codes but not separated by commas. For example: 9001190015900179003490037900439004790048900569006 19006290301 9030190301 90302 Well when I use a foreach loop as follows: foreach ($range as $r) {echo $r.",";} the $range array behaves like any normal array yielding: 90011,90015,90017,90034,90037,90043,90047,90048,90056,90061,90062,90301 ,90301,90301 ,90302, So why in the world is the implode function not working? Here is my code. //Retrieve the zip codes within range. // Connect to the database. require('config.php'); //Retrieve longitude and latitude of logged in member. $query = "SELECT* FROM members INNER JOIN zip_codes ON members.zip = zip_codes.zip WHERE members.member_id = '{$_SESSION['id']}'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $my_lon = $row['lon']; $my_lat = $row['lat']; //Query all longitudes and latitudes in database. $query2 = "SELECT* FROM zip_codes INNER JOIN members ON members.zip = zip_codes.zip "; $result2 = mysql_query($query2); while ($row2 = mysql_fetch_assoc($result2)) { //Define array to hold zips found within range. $range = array(); if((rad2deg(acos(sin(deg2rad($my_lat))*sin(deg2rad($row2['lat'])) +cos (deg2rad($my_lat)) * cos (deg2rad($row2['lat'])) * cos(deg2rad($my_lon - $row2['lon'])) ) ) )*69.09 <= $distance ) { $range[] = $row2['zip']; } //Implode the range arrary. $range = implode(',' , $range); echo $range; }//End of while loop. I have a problem with the below code: Code: [Select] <?php $sql_ranks = ("SELECT vtp_members.id, vtp_members.name, vtp_members.teamleader, teams.team_name, count(vtp_tracking.id) surfs FROM vtp_members, vtp_tracking, teams WHERE vtp_members.team_id=".$_GET['t']." AND vtp_tracking.credit_members_id=vtp_members.id AND vtp_tracking.action_date > '$last_sunday' AND vtp_tracking.action_date < '$next_sunday' GROUP BY teams.team_name ORDER BY surfs DESC"); $rsranks = mysql_query($sql_ranks); echo "<br><table align='center' valign='top' border='0' width='300px'> <tr><td colspan='2' align='center'><font size='2px'><b>Team Rankings (Current Week)</b></font></td></tr> <tr><td><font size='2px'><b>Team</font></td><td align='right'><font size='2px'>Total Surfs</font></td></tr>"; while ($row = mysql_fetch_array($rsranks)) { echo "<tr><td><font size='2px'><b>".$row[team_name]."</font></td><td align='right'><font size='2px'>".$row[surfs]."</font></td></tr>";} echo "</table>"; ?> Problem is that the last output (".$row[surfs].") is the same for all teams. It seems it is not making a total of all id's and not per team_name. anyone can see what I am doing wrong. I need to sort by team_name and the surfs should display the total of the members with team_id is ".$_GET['t']." I created a function called converter. My code doesn't look like it processes anything after the first if . This is what is displayed in browser. Convert a String original string: roses Are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... converted string: roses are red, violets are blue.... <html> <head> <title>Create a PHP Function to Convert a String</title> </head> <body bgcolor="pink"> <h2>Convert a String</h2> <?php $phrase = "roses Are red, violets are blue...."; function converter($arg1, $arg2){ if($arg1="lower"){ return strtolower($arg2); } elseif ($arg1="upper"){ return strtoupper($arg2); } else /* if($arg1="title")*/{ return ucwords($arg2); } } print "original string: ".$phrase."<br />"; print "converted string: ".converter("upper",$phrase)."<br />"; print "converted string: ".converter("lower",$phrase)."<br />"; print "converted string: ".converter("title",$phrase)."<br />"; ?> </body> </html> I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } |