Jump to content
Greywacke

PHP Structural Conflagration

Recommended Posts

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 by Greywacke
Better clarity

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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 by Greywacke
Better clarity

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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 by Funce

Share this post


Link to post
Share on other sites

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!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...