Greywacke Posted January 30, 2019 Share Posted January 30, 2019 (edited) Hi again, moved the topic to a new one because it no longer uses PCRE. I have the physical problem of having lost my dev pc and 24" screens, now having to make do with android on a 3.5" touchscreen. So the issue i have encountered is again a likeness of this time a bit more physically - "not being able to see the forest for the trees", as my viewing area has been greatly diminished. The code is below, with the php error_log thereafter. <?php $t = intval($_GET["t"]); switch ($t) { case 1: header('Content-Type: Text/XML'); break; case 2: header('Content-Type: Text/JavaScript'); break; case else: header('Content-Type: Text/HTML5'); ?><!DOCTYPE html> <html lang="en-za"> <head> <meta charset="UTF-8"> <title>*** Test Page</title> </head> <body> <p><a href="http://***.com/default.php?t=0&u=Sof00207&f=c&r=45">*** Test Page</a></p><br /> <p> <pre><? /* Initiate Variables for URL: http://***.com/default.php?t=0&u=Sof00207&f=c&r=45 1. Key Field: C 2. Key Row: 45 3. Account Number: Sof00207 4. Month: G 5. Number Of Licenses: 5 6. Active: Y/N: J 7. Licences Used: 3 8. Year: J 9. Module 1: A 10. Module 2: 1 11. Module 3: B 12. Module 4: 0 */ $f = strtoupper($_GET["f"]); $r = intval($_GET["r"]); $f = dirname(__FILE__) . "/RegUploads/" . $_GET["u"] . "#" . $f . $r . ".xml"; print $f . "\r\n\r\n"; if (file_exists($f)) { $ret = file_get_contents($f); print htmlentities($ret); } $servername = "localhost"; $username = "***"; $password = "***"; $dbname = "***"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // echo "Connected successfully"; $q = intval($_GET["q"]); switch ($q) { case 0: // Return Encryption Key by Field A/B/C/D & Row ID // Define SQL String $sql = "SELECT * FROM `Sleutels` WHERE `ID` = " . $r . ";"; $result = $conn->query($sql); if ($result->num_rows > 0) { print "\"" . $sql . "\"<br />\r\n"; // output data of each row while($row = $result->fetch_assoc()) { print "Key: " . htmlencode($row[$f]). "<br />\r\n"; }; } else { print "\"" . $sql . "\"<br />\r\n"; print "0 results<br />\r\n"; }; break; case 1: echo "q equals 1"; break; case 2: echo "q equals 2"; break; }; ?></pre> </p> </body> </html><? }; $conn->close(); ?> [30-Jan-2019 19:42:33 UTC] PHP Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/dwtnfwfv/public_html/default.php on line 11 Edited January 30, 2019 by Greywacke Better clarity Link to comment Share on other sites More sharing options...
justsomeguy Posted January 30, 2019 Share Posted January 30, 2019 It's pointing out that "else" does not go after "case". Link to comment Share on other sites More sharing options...
Greywacke Posted January 31, 2019 Author Share Posted January 31, 2019 Ah yeah, *facepalms* lol Still though, [31-Jan-2019 13:40:55 UTC] PHP Fatal error: Call to a member function format() on boolean in /home/dwtnfwfv/public_html/default.php on line 91 Which has to do with the following portion of code, the winning answer at expertsexchange: placeholder Link to comment Share on other sites More sharing options...
Greywacke Posted January 31, 2019 Author Share Posted January 31, 2019 (edited) Ah yeah, *facepalms* lol Still though, [31-Jan-2019 13:40:55 UTC] PHP Fatal error: Call to a member function format() on boolean in /home/dwtnfwfv/public_html/default.php on lince 91 Which has to do with the following portion of code, the winning answer at expertsexchange: $monthNum = $row["month"]; $dateObj = DateTime::createFromFormat('!m', $monthNum); $monthName = $dateObj->format('F'); // eg. January - December print "Month: " . $monthName . "<br />\r\n"; Edited January 31, 2019 by Greywacke Better clarity Link to comment Share on other sites More sharing options...
Ingolme Posted January 31, 2019 Share Posted January 31, 2019 According to the PHP manual for createFromFormat() Quote Returns a new DateTime instance or FALSE on failure. This means that the value contained in $monthNum is not valid and the function has returned a boolean instead of a DateTime object. Link to comment Share on other sites More sharing options...
Funce Posted January 31, 2019 Share Posted January 31, 2019 (edited) As far as I'm aware, Date objects require complete dates to be created. (Needs a Year and a Day in addition to the month so the whole object works) You'll want to put some placeholder year and day values in the format YYYY-MM-DD. Something like this would work to create your Date object. $dateObj = new DateTime('2000-' . $monthNum . '-01'); However if you wanted something more concise, just the month number, you could use this. $monthName = date('F', strtotime('2000-' . $monthNum . '-01')); Edited January 31, 2019 by Funce Link to comment Share on other sites More sharing options...
Greywacke Posted February 2, 2019 Author Share Posted February 2, 2019 Yes sorry this post is so late but i realised that a day after posting. This isue has been resolved, thouh - thanks nonetheless for clearing it up here, though! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now