I am writing a php script which does the following:
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.
";
$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!
"};
}
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!";
echo "<a href="write.php">Back</a>";
}
echo "after database stuff";
?>
You need to change your select in order to surround $folder
with quotes:
$query = "SELECT 'folderID' FROM folder WHERE name = '$folder';";
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.
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!