Paul-D Posted September 23 Share Posted September 23 Hi I have an error on line $test = "NULL"; in function GetAllData($StartDate, $View) { $test = "NOT NULL"; if($View == NULL { $test = "NULL"; // error Parse error: syntax error, unexpected token ";" in /vhost/d/e/s/desmond-otoole.co.uk/www/bank2/secure/SecureFunctionsBankPDO.php on line 32 } StoreData($StartDate . " Len: " . strlen($View) . "- " . $test); // *** Store data to trap this error *** $pdo = connectDB(); if($View == 'Show' or $View == 'Show+' . if($View == NULL) //Desmond. or Desmond.. { $sqlAllData = "SELECT * FROM Bank_Data WHERE EntryDate > ? AND EntryDate <= DATE_ADD(?, INTERVAL 6 WEEK) ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute( [ $StartDate, $StartDate] ); return $stmt; } if($View == 'Total' or $View == 'Database' ) { $sqlAllData = "SELECT * FROM Bank_Data ORDER BY EntryDate ASC, Output"; $stmt = $pdo->prepare($sqlAllData); $stmt->execute(); return $stmt; } } Seems okay to me. Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/ Share on other sites More sharing options...
mac_gyver Posted September 23 Share Posted September 23 firstly, this question is a php question. not a mysql question. the syntax of your if() {} conditional statement is broken. the ) is missing. there's no guarantee that the incorrect value is a NULL. i showed you in a previous thread how you can use var_export() to cause the actual value to be used in the storedata(...) call. Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659856 Share on other sites More sharing options...
gizmola Posted September 23 Share Posted September 23 Beyond what mac already found, the condition following it is also broken: if($View == 'Show' or $View == 'Show+' . if($View == NULL) Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659857 Share on other sites More sharing options...
Paul-D Posted September 23 Author Share Posted September 23 As I said previously I can not use storedata(...) here. I am entering this data into a database table with the field value as Page as varchar(20). I have used this $test = "NOT NULL"; if($View === NULL) $test = "NULL"; And add this into the database field. When the problem re accours I can check the database. Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659861 Share on other sites More sharing options...
gizmola Posted September 24 Share Posted September 24 6 hours ago, Paul-D said: As I said previously I can not use storedata(...) here. I am entering this data into a database table with the field value as Page as varchar(20). I have used this $test = "NOT NULL"; if($View === NULL) $test = "NULL"; And add this into the database field. When the problem re accours I can check the database. I just pasted the code you provided. Along with what Mac stated, you have syntax errors. He already explained this to you, as your code is missing the required end parentheses. I have no idea what you were trying to do with the code in my message -- it makes on sense, and looks like you accidentally copy/pasted a snippet from somewhere. Again, all conditions have to have parentheses around them! if (condition) { // condition evaluates to true } else { // condition evaluated to false } Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659864 Share on other sites More sharing options...
Paul-D Posted September 24 Author Share Posted September 24 (edited) Update on what I said previously. I am entering into a database table the following Date of entry plus strlen($View) . $test [Is this NULL] The result of $test = "NOT NULL"; if($View === NULL) $test = "NULL"; I have got 2025-09-22 (0) NOT NULL a string that is lenthe 0 and it is NOT NULL Sugestion was to use var_export() so I have tested this $View = $_SESSION['CounterValue']; echo "Value: " . var_export($View); exit; Result: ''Value: <nothing follows> In the php manual https://www.php.net/manual/en/function.var-export.php All I get is the contents of the variable nothing else. What was I suposed to see here? Type of variable[string]? IS NULL? value if exists all the under the bonnet info on this variable. All I got was nothing. What my method showd was, it is NOT NULL and a zero length string. Which is more information than I got from var_dump() Edited September 24 by Paul-D Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659874 Share on other sites More sharing options...
gizmola Posted September 24 Share Posted September 24 We are having issues understanding what your question is. These are 2 different things in PHP. A variable that is set to null has no value and no type. <?php $var = null; $str = ''; echo gettype($var) . PHP_EOL; echo gettype($str) . PHP_EOL; var_export($var); echo PHP_EOL; var_export($str); Output: NULL string NULL '' If you want to use var_export as a string, you need to pass true as the 2nd parameter. echo "Value: " . var_export($View, true); Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659887 Share on other sites More sharing options...
mac_gyver Posted September 24 Share Posted September 24 (edited) the OP was already told how to use var_export - https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#findComment-1657999 then given a copy/paste use - https://forums.phpfreaks.com/topic/330113-ongoing-problem-with-missing-session-variables/#comment-1659430 edit: and this problem isn't going to go away until the only session variable that is an input to this 'statement' code is the logged in user's id, so that the only code that affects what the processing is and what is displayed on this page, is the code on this page, and not in any processing on other pages. Edited September 24 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659889 Share on other sites More sharing options...
gizmola Posted September 24 Share Posted September 24 Yes it does seem that we have an issue with the OP not reading responses carefully, nor absorbing the feedback and comments. Appreciate you pointing this out. Quote Link to comment https://forums.phpfreaks.com/topic/330656-unexpected/#findComment-1659891 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.