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? Quote Link to comment 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 } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
papaface Posted March 10, 2007 Share Posted March 10, 2007 Close Rather, mark this thread as solved. Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 10, 2007 Author Share Posted March 10, 2007 But it's not Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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"; Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.