/    Sign up×
Community /Pin to ProfileBookmark

Php code showing blank result page.

Hi.
I am trying to create an image upload form with html and php. The form is ok and shows. But when I add my php code, I get a blank page when I visit the page in my browser. Can somebody please check my code and point out what is wrong with my php code? Help appreciated.
Thank you.

Here is my code :

[CODE]<html>
<head>
<title>dfd</title>
</head>
<body>
<form method=”post” action=”test.php” enctype=”multipart/form-data”>
<input type=”hidden” name=”maxFileSize” value=”300000″ />
<input type=”text” name=”name” id=”name”/><br /><br />
<input type=”text” name=”score” id=”score”/><br /><br />
<input type=”file” name=”screenshot” id=”screenshot”/><br /><br />
<input type=”submit” name=”submit” id=”submit” />
</form>

<?php
if(isset($_POST[‘submit’])){
$name=$_POST[‘name’];
$score=$_POST[‘score’];
$screenshot=$_FILES[‘screenshot’][‘name’];
$screenshot_size=$_FILES[‘screenshot’][‘size’];
$screenshot_type=$_FILES[‘screenshot’][‘type’];
if(!empty($name) && !empty($score) && !empty($screenshot)){
require_once(‘appvars.php’);
if((($screenshot_type == ‘image/png’) || ($screenshot_type == ‘image/jpeg’) || ($screenshot_type == ‘image/pjpeg’) || ($screenshot_type == ‘image/gif’)) && ($screenshot_size > 0) && ($screenshot_size <= TEST_MAXFILESIZE)){
if($_FILES[‘screenshot’][‘error’] == 0){
$target = TEST_UPLOADPATH.$screenshot;
if(move_uploaded_file($_FILES[‘screenshot’][‘tmp_name’], $target)){
require_once(‘connectvars.php’);
$query = “INSERT INTO `test` VALUES (0, ‘$name’, ‘$score’, ‘$screenshot’, NOW())”;
$result = mysqli_query($dbConnect, $query);
or die (‘Could not add your highscore. Please try again’);

echo ‘Thank you for adding your score ‘ . $name . ‘<br />’;
echo ‘Your score is ‘ . $score . ‘<br />’;
echo ‘<img src = “‘ . TEST_UPLOADPATH.$screenshot . ‘” alt = “Score image” /><br />’;

$name=””;
$score=””;
$screenshot=””;

mysqli_close($dbConnect);
}
}
else {
echo ‘Error uploading screenshot. High score not added. Please try again’;
}
}
else{
echo ‘High score not added. Your image should be either a PNG, GIF or JPEG and the size should not exceed ‘ . MAX_FILE_SIZE/1024 . ‘kB’;
}
}
else {
echo ‘<p>Please enter all the fields</p>’;
}
}
?>
</body>
</html>[/CODE]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 17.2015 — First thing: did you do a "view page source" in your browser on the blank page to see if it includes any error info that did not get displayed (because the browser got confused by the broken HTML markup that ensued)?
Copy linkTweet thisAlerts:
@NogDogMay 17.2015 — [code=php]
$result = mysqli_query($dbConnect, $query);
or die ('Could not add your highscore. Please try again');
[/code]
...should be...
[code=php]
$result = mysqli_query($dbConnect, $query)
or die ('Could not add your highscore. Please try again');
[/code]

Can you spot the difference (besides the cosmetic indent change)? ?
Copy linkTweet thisAlerts:
@sunoy14authorMay 17.2015 — [code=php]
$result = mysqli_query($dbConnect, $query);
or die ('Could not add your highscore. Please try again');
[/code]
...should be...
[code=php]
$result = mysqli_query($dbConnect, $query)
or die ('Could not add your highscore. Please try again');
[/code]

Can you spot the difference (besides the cosmetic indent change)? ?[/QUOTE]


Ah! That little pesky semicolon. I get stuck for hours because of such little errors ?

Thanks for the help. Script working fine now.

You've got a sharp eye. You should join the snipers' squad ?
Copy linkTweet thisAlerts:
@rootMay 17.2015 — [code=html]<input type="submit" name="submit" id="submit" />[/code] to [code=html]<input type="submit" name="Submit" id="submit" />[/code]

[code=php]if(isset($_POST['submit'])){[/code] to [code=php]if(isset($_POST['Submit']) and $_SERVER['REQUEST_METHOD']=="POST"){[/code]

[code=php]if((($screenshot_type == 'image/png') || ($screenshot_type == 'image/jpeg') || ($screenshot_type == 'image/pjpeg') || ($screenshot_type == 'image/gif')) && ($screenshot_size > 0) && ($screenshot_size <= TEST_MAXFILESIZE)){[/code] to [code=php]$iTypes = array('image/png','image/jpeg','image/pjpeg','image/gif');
if( in_array($screenshot_type, $iTypes) && $screenshot_size <= TEST_MAXFILESIZE){[/code]


$query = "INSERT INTO <span><code>test</code></span> VALUES (0, '$name', '$score', '$screenshot', NOW())"; to $query = sprintf( "INSERT INTO <span><code>test</code></span> VALUES (0, '%s', '%s', '%s', NOW())",$name,$score,$screen_shot);

on this line [code=php]$result = mysqli_query($dbConnect, $query);
or die ('Could not add your highscore. Please try again');[/code]
you have a ; which terminates that line leaving an "or die('Could not add your highscore. Please try again');[/code]

You could restructure the page so you perform some checks earlier than later, such as when a page is requested, the script executes, sends out the HTML, stumbles across a PHP block of code about uploads., much beeter if you check for a form submission first and then if its not spit out an upload page.
Copy linkTweet thisAlerts:
@NogDogMay 17.2015 — ...

You've got a sharp eye. You should join the snipers' squad ?[/QUOTE]


I also use an editor that's pretty good at detecting syntax errors and pointing my eye to the right area of the script to look at. ?

https://confluence.jetbrains.com/display/PhpStorm/PhpStorm+Early+Access+Program
Copy linkTweet thisAlerts:
@duck001May 18.2015 — Keep checking Log files for errors, it would of given you a hint of this syntax error. In Linux you can tail a log for live output: tail -f /var/log/apache2/error.log

error.log will be your friend ?
×

Success!

Help @sunoy14 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...