View Full Version : What is wrong with this code

08-30-2007, 09:27 PM
I have no idea what is wrong with this code... if someone could help me that would be great it would be so awesome!

$input2 = $_POST["Name"];
$input3 = $_POST["Email"];
$input4 = $_POST["time"];
$input5 = $_POST["TermsOfService"];
$input6 = $_POST["3p42r3ad3a4than32"];
$input7 = $_POST["Title"];
$input8 = $_POST["Description"];
$input9 = $_POST["file1"];
$input10 = $_POST["file2"];
$empty = '';
$agree = 'Agreed';
$a = '329r8g';

$c = '1';
$d = '0';
$valid = '5';
if ($empty == $input2) {
echo "Your Name cannot be blank.<br>";
} else {

if ($empty == $input3) {
echo "Your EmailAddress cannot be blank.<br>";
} else {
if ($empty == $input4) {
echo "Make sure your clock is set to the correct date, we record dates so we can know exactly when you submitted your files...<br>";
} else {
if ($empty == $input5) {
echo "You must agree to the Terms Of Service.<br>";
} else {
if ($empty == $input6) {
echo "There is an error with our form we are sorry for this problem we will fix it tomorrow.<br>";
} else {
if ($d == $valid){
$upload_dir = "submitions/";
$num_files = 2;
//the file size in bytes.
$size_bytes =20480000; //51200 bytes = 50KB.
//Extensions you want files uploaded limited to.
$limitedext = array(".gif",".jpg",".jpeg",".png",".bmp",".mov",".mpg",".mpeg");

//check if the directory exists or not.
if (!is_dir("$upload_dir")) {
die ("Error: The directory <b>($upload_dir)</b> doesn't exist because we are in the process of the weekly upload.");
//check if the directory is writable.
if (!is_writeable("$upload_dir")){
die ("Error: The directory <b>($upload_dir)</b> is NOT writable, Please click contact and then contact technical support to tell them this problem.");

//if the form has been submitted, then do the upload process
//infact, if you clicked on (Upload Now!) button.
if (isset($_POST['upload_form'])){

echo "<h3>Upload results:</h3>";

//do a loop for uploading files based on ($num_files) number of files.
for ($i = 1; $i <= $num_files; $i++) {

//define variables to hold the values.
$new_file = $_FILES['file'.$i];
$file_name = $new_file['name'];
//to remove spaces from file name we have to replace it with "_".
$file_name = str_replace(' ', '_', $file_name);
$file_tmp = $new_file['tmp_name'];
$file_size = $new_file['size'];

# this code will check if the files was selected or not. #

if (!is_uploaded_file($file_tmp)) {
//print error message and file number.
echo "File $i: Not selected.<br>";

$ext = strrchr($file_name,'.');
if (!in_array(strtolower($ext),$limitedext)) {
echo "File $i: ($file_name) Wrong file extension. <br>";

if ($file_size > $size_bytes){
echo "File $i: ($file_name) Faild to upload. File must be <b>". $size_bytes / 1024 ."</b> KB. <br>";

echo "File $i: ($file_name) already exists.<br>";

if (move_uploaded_file($file_tmp,$upload_dir.$file_name)) {
echo "File $i: ($file_name) Uploaded.<br>";
echo "File $i: Faild to upload.<br>";
}#end of (move_uploaded_file).

}#end of (file_exists).

}#end of (file_size).

}#end of (limitedext).

}#end of (!is_uploaded_file).

}#end of (for loop).
# print back button.
echo "<a href=\"$_SERVER[PHP_SELF]\">back</a>";
//else if the form didn't submitted then show it.
echo " <h3>Select files to upload!.</h3>
Max file size = ". $size_bytes / 1024 ." KB";
echo " <form method=\"post\" action=\"$_SERVER[PHP_SELF]\" enctype=\"multipart/form-data\">";
// show the file input field based on($num_files).
for ($i = 1; $i <= $num_files; $i++) {
echo "File $i: <input type=\"file\" name=\"file". $i ."\"><br>";
echo " <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"$size_bytes\">
<input type=\"submit\" name=\"upload_form\" value=\"Upload Now!\">
$data = "<table border='1'>
<tr><td>User IP Address:</td><td>$input1</td></tr>
<tr><td>Email Address:<td>$input3</td></tr>
<tr><td>Date Submitted:</td><td>$input4</td></tr>
<tr><td>Description</td><td><textarea cols='50' rows='5'>$input6</textarea></td></tr>
<tr><td>File 1 Location:</td><td>$file1</td></tr>
<tr><td>File 2 Location:</td><td>$file2</td></tr></table>";

if (is_writable($filename)) {
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";

// Write $somecontent to our opened file.
if (fwrite($handle, $data) === FALSE) {
echo "Cannot write to file";

echo "Success your information has been submitted! Now please submit your files...";


} else{
echo "You must fill out all fields properly";


08-30-2007, 09:31 PM
Mr Mechanic, what is wrong with my car? ;)

If you want to know "what's wrong" with the code, you have to tell us what you wanted to have happen or expected to happen, what did or did not happen as expected, and any error messages you received.

08-30-2007, 09:36 PM
Mr Mechanic, what is wrong with my car?

Oh sorry, my bad lol...
Ok so everything works till I get to the last validation which is this:

if ($d == $valid){

What is supposed to happen is that when d equals the value of valid then it shows the upload form and then submits the data from the previous page... *which is everything past this*

if ($d == $valid){
The validation process works, just when everythings valid it doesn't show anything on the page...

Please if someone could help that would be awesome!

08-30-2007, 11:07 PM
If someone could help me that would be great!!!!!

08-30-2007, 11:30 PM
Are you sure $d is being incremented? I'm pretty sure your plus symbols are on the wrong side of the variable, ie, it should be $d++;

08-30-2007, 11:32 PM
Let me try that, but I know when I was testing to see if it worked it did add it up...

08-30-2007, 11:34 PM
Thanks!!!!!! IT WORKS!!!!

08-31-2007, 12:41 AM
Interesting... other languages provide ++var as a way to increment before the expression is evaluated, but I guess PHP does not.

08-31-2007, 12:42 AM
blah i wouldnt waste your time Fum.. take a look at his last thread, i try help him and he got rude... F him..

08-31-2007, 03:54 AM
(From the manual)

++$a Pre-increment Increments $a by one, then returns $a.
$a++ Post-increment Returns $a, then increments $a by one.
--$a Pre-decrement Decrements $a by one, then returns $a.
$a-- Post-decrement Returns $a, then decrements $a by one.

08-31-2007, 07:31 AM
Hrmm yeah I thought PHP would support ++$var... guess the OP is a little confused as to what fixed his code. :rolleyes: