0

I am writing a php script which does the following:

  • Accepts incoming POST data from an article editing page.
  • Checks if the dropdown list on the previous page was set to "Create New Folder".
  • If so it checks if something is in the textbox named foldercreate.
  • Inserts this into the database if it is.
  • If not it creates a Miscellaneous folder in the database and uses that in the insert.

The trouble is I keep getting a white screen when I hit the form submit button on the previous page. It shows savearticle.php in the address bar but nothing else. It won't even print out error messages. I must have rewritten this about three times now so forgive any logic errors in the code but it should be working as far as I can see. I just want to make sure it's working in its present form before going any further.

The echo statements throughout the code are something I found useful for debugging in the past but it doesn't display a single one.

In the functions.php include I am just using the database connection information as I use this across multiple pages without issue.

Any help would be appreciated as this is getting pretty frustrating.

<?php
echo "start of file";
include_once 'functions.php';
echo "after include";
$title          = $_POST[ 'title' ];
$body           = $_POST[ 'body' ];
$folderselect   = $_POST[ 'folderselect' ];
$foldercreate   = $_POST[ 'foldercreate' ];
$newfolderflag  = 99;
echo "after variables";
if ($folderselect === "Create New Folder") {
    $folder = $foldercreate;
    $newfolderflag = 0; 
    } else if ($foldercreate == NULL && $folderselect === "Create New Folder"){
    $folder = "misc";
    echo "Nothing selected. Putting in Miscellaneous folder.\n\n";
    $newfolderflag = 0;
    } else {
        $folder = $folderselect;
        }

if ($newfolderflag === 0) {
    $query = "INSERT INTO folder ('name') VALUES ('$folder');";
    if (mysqli_query($db, $query) == TRUE) { echo "New folder created successfully!\n\n"};
}
echo "after if statements";
$query = "SELECT 'folderID' FROM folder WHERE name = $folder;";
$result = mysqli_query($db, $query);
$row = array();
$row = mysqli_fetch_array($result);
$folder = $row['0'];

$query  = "INSERT INTO article ( title, body, folderID, userID ) VALUES ('$title', '$body', '$folder', '$user');";
if (mysqli_query($db, $query) === TRUE) {
    echo "Article Saved!\r";
    echo "<a href="write.php">Back</a>";
    }
echo "after database stuff";

?>
moonwave99
  • 21,957
  • 3
  • 43
  • 64

3 Answers3

1

You need to change your select in order to surround $folder with quotes:

$query = "SELECT 'folderID' FROM folder WHERE name = '$folder';";
MillaresRoo
  • 3,808
  • 1
  • 31
  • 37
  • 1
    Nice catch. OP, you should consider prepared statements for both security and avoiding mistakes like this. See here for examples: http://www.php.net/manual/en/mysqli-stmt.bind-param.php – Jeremy Kendall Jan 01 '14 at 17:34
  • Thank you very much! It's always the little things that cause the most stress. – user2898982 Jan 01 '14 at 23:27
0

A while screen means a Fatal error happened in parsing (which almost always means bad syntax, like a missing semicolon). Add the following line to the top of your script and see what the error is.

ini_set('display_errors', 1);

Also, using an IDE that color codes, like NetBeans, can help you tremendously by highlighting syntax issues.

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • I tried that previously but it didn't display any error messages. I'm using Sublime Text 2 (which is fantastic) and I can't seem to spot any syntax errors. – user2898982 Jan 01 '14 at 16:46
0

First, error reporting and display should be cranked all the way up in your dev environment. In your php.ini, you should have the following:

error_reporting = -1
display_errors = 1
display_startup_errors = 1

You can recreate those settings in your script for debugging purposes only by adding the following at the top of your current script (must be removed after debugging):

error_reporting(-1);
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);

Now try again. If you still get nothing, then replace your first debugging echo with a die() statement. I usually use die('wtf?');. If wtf? shows up on the page, then cut and paste it farther down the page. Continue until the white screen reappears and you've found your problem.

Good luck!

Jeremy Kendall
  • 2,869
  • 17
  • 17