jlgray48 Posted April 24, 2007 Share Posted April 24, 2007 What is the php code to determine if a variable is null or empty? Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/ Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 if ($variable == FALSE) if (!isset($variable)) if ($variable == "") This MIGHT work (Never tried): if (!$variable) Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236577 Share on other sites More sharing options...
fert Posted April 24, 2007 Share Posted April 24, 2007 if(empty($var)) There are lots of ways Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236578 Share on other sites More sharing options...
jlgray48 Posted April 24, 2007 Author Share Posted April 24, 2007 absolutely amazing, how did you do that Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236580 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 There are lots of ways Yes there are! Too many! I end up using about 3-4 different ways in one script. I will use clips from an old script, but the new one is using a different way... It becomes quite disgusting! Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236581 Share on other sites More sharing options...
jlgray48 Posted April 24, 2007 Author Share Posted April 24, 2007 Can you help me with this code? <?php $Item1 = $_REQUEST[item 1]; $Item2 = $_REQUEST[item 2]; $Item3 = $_REQUEST[item 3]; $conn=mysql_connect("127.0.0.1", "odbc", "") ; mysql_select_db("php012",$conn); For ($i = 1; $i <=3 ; $i+=1) { While $Item.$i == " " { $sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ; mysql_query($sql,$conn); } ?> Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236582 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 Based on your previous question, you don't want to use that: While $Item.$i == " " { You would want to use: While $Item.$i == "" { The space tells php that as long as $Item.$i equals a space do this... Or I suppose you could replace the "" with any of the above suggestions such as FALSE... Edit: Also, for your for loop: For ($i = 1; $i <=3 ; $i+=1) you could use For ($i = 1; $i <=3 ; $i++) Instead. $i++ is the same as $i=+1.. Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236583 Share on other sites More sharing options...
jlgray48 Posted April 24, 2007 Author Share Posted April 24, 2007 I think the $item.$i is incorrect can you take a look. Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236587 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 Ooo.. I don't know how I missed this! While $Item.$i == " " { $sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ; mysql_query($sql,$conn); } should be this: while ($Item.$i == "") { $sql = "Update inventorytable set Itemquantity = Itemquantity -1 where ItemID = $Item.$i" ; mysql_query($sql,$conn); } As far as the "$Item.$i" goes, I don't know what your trying to accomplish... Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236588 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 Could you explain to me exactly what your trying to do, I might be able to help you better. I don't know anything about the SQL lite or what ever it is that your using.... Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236592 Share on other sites More sharing options...
bobleny Posted April 24, 2007 Share Posted April 24, 2007 Cancel that I think I figured out what you wanted. Please check your other thread. Link to comment https://forums.phpfreaks.com/topic/48386-solved-what-is-the-code-to-determine-if-a-variable-is-holding-anything-null-empty/#findComment-236602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.