Greaser9780 Posted March 10, 2007 Share Posted March 10, 2007 I am trying to create a series of if statements. If the var is equal to null it should update the db. If it is not equal to null and has a value it should go to the next if statement. I have tried if ($var = 'NULL") and it always lets me write to the db even if there is a greater value there. I have tried if($var == 'NULL') and it never lets me write to the db no matter what value is in the db. I have also tried each of these with = '0' instead of null. Any suggestions? Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/ Share on other sites More sharing options...
papaface Posted March 10, 2007 Share Posted March 10, 2007 Try if (empty($var)) { //code you want done if theres nothing assigned to $var } Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204526 Share on other sites More sharing options...
Greaser9780 Posted March 10, 2007 Author Share Posted March 10, 2007 Close, the problem is I have the default set to null in the db. So it skips right over that accepting null as a value. Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204534 Share on other sites More sharing options...
papaface Posted March 10, 2007 Share Posted March 10, 2007 Close Rather, mark this thread as solved. Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204535 Share on other sites More sharing options...
Greaser9780 Posted March 10, 2007 Author Share Posted March 10, 2007 But it's not Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204536 Share on other sites More sharing options...
marcus Posted March 10, 2007 Share Posted March 10, 2007 In you query define it. "INSERT INTO `tablename` (`value`,`NULLvaluename`) VALUES('$val','$hello')"; He never said to close it. He said "Close" as in near to efficiency. Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204537 Share on other sites More sharing options...
Greaser9780 Posted March 10, 2007 Author Share Posted March 10, 2007 Using update since the default is null. I am using update since I need a where clause to describe which row to update. Otherwise I would just use INSERT. WHERE clause doesn't really work with insert Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204539 Share on other sites More sharing options...
Greaser9780 Posted March 10, 2007 Author Share Posted March 10, 2007 Here is some code: $sql2=mysql_query("SELECT * FROM pd WHERE teamid= '$teamid'"); $res2=mysql_fetch_array($sql2); if ($res2['pd1'] = 'NULL' ) { $upd=mysql_query("UPDATE pd SET pd1='$playername',pos1='$pos' WHERE teamid='$teamid'"); require("pdform.php"); exit(); } echo "BLAH"; Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204544 Share on other sites More sharing options...
per1os Posted March 10, 2007 Share Posted March 10, 2007 use the is_null function http://us2.php.net/manual/en/function.is-null.php --FrosT Link to comment https://forums.phpfreaks.com/topic/42162-solved-var-null-if-statement-problems/#findComment-204548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.