PDA

View Full Version : New found form problems!



abcdme
06-28-2007, 03:38 PM
Hi i'm dan from new zealand, right next to my home land australia.
I have been writing php scripts for two years now and just recently none of them have been working.

Please help me out as best as you can, i'm sure it is only something simple.


----------------Form 1--------------------------
<?php

// ---- Customized form script for the HBRC---------------

// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$f1 = addslashes($_POST['f1']);
@$f2 = addslashes($_POST['f2']);
@$f3 = addslashes($_POST['f3']);
//---------------------------------------------------------------
//-------Loop for Image relevant variables----------------
for ($i = 1; $i <= 3; $i++)
{
$fl = "fl$i";
@$fl[$i]= $_FILES[$Image_Upload]['name'];
@$fl_Size[$i]= $_FILES[$Image_Upload]['size'];
@$fl_Name[$i]= $_FILES[$Image_Upload]['name'];
@$fl_Temp[$i]= $_FILES[$Image_Upload]['tmp_name'];
}
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
//---Upload the files if they exist---------------------------------
for ($i = 1; $i <= 8; $i++)
{
if ($fl_Size[$i] < $size and $fl_Size[$i] >0)
{
$uploadFile = "uploads/".$fl_Name[$i];
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $Image_Upload_Temp[$i] , $uploadFile);
chmod($uploadFile, 0644);
$Image_URL[$i] = "../images/uploads/".$fl_Name[$i];
}
}
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");

//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n"
. "Reply-To: $pea\n";
$nd_subject = "Upload to the HBRC Website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New File(s):\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Desired Password: $dp\n"
. "-------------------------------------------\n"
. "Fees are up to date: $mf\n"
. "-------------------------------------------\n";
for ($i = 1; $i <= 8; $i++)
{
if (@$Image_Upload_Size[$i] >0)
{
$nd_message .= "Link to image $i : $Image_URL[$i] \n
. "-------------------------------------------\n";
}
}
. "-------------------------------------------\n"
$nd_message .= "Date of Submission : $date\n"
. "-------------------------------------------\n"
&mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");

?>

----------------------------------Form 2 ------------------------------------
<?php

// ---- Customized form script for the HBRC---------------

// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$dp = addslashes($_POST['dp']);
@$ea = addslashes($_POST['ea']);
@$mf = addslashes($_POST['mf']);
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");

//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n"
. "Reply-To: $pea\n";
$nd_subject = "Query from the HBRC website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New Query:\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Desired Password: $dp\n"
. "-------------------------------------------\n"
. "Fees are up to date: $mf\n"
. "-------------------------------------------\n"
$nd_message .= "Date of Submission : $date\n"
. "-------------------------------------------\n"
&mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");

?>

-------------------------------------Form 3 -------------------------------
<?php

// ---- Customized form script for the HBRC---------------

// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$dp = addslashes($_POST['pn']);
@$ea = addslashes($_POST['ea']);
@$mf = addslashes($_POST['cm']);
@$mf = addslashes($_POST['qy']);
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");

//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n"
. "Reply-To: $ea\n";
$nd_subject = "Query from the HBRC website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New Query:\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Phone Number: $pn\n"
. "-------------------------------------------\n"
. "Query: $qy\n"
. "-------------------------------------------\n"
. "Contact Method: $cm\n"
. "-------------------------------------------\n"
$nd_message .= "Date of Submission : $date\n"
. "-------------------------------------------\n"
&mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");

?>

--------------------------------The end --------------------------

Thank you for your time. I am in need of these to work as it is for an assignment due in 5 hours time!!!!!

navaldesign
06-28-2007, 05:27 PM
These scripts are a combination of ABVFP core with some scripts i had posted a year or so ago. Please note that there are both syntax errors as well as logical errors (you are using variables that have NOT been defined). Look below (please note that there could be other errors as well, i did not test the scripts.):

<?php
// ---- Customized form script for the HBRC---------------
// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$f1 = addslashes($_POST['f1']);
@$f2 = addslashes($_POST['f2']);
@$f3 = addslashes($_POST['f3']);
//---------------------------------------------------------------
//-------Loop for Image relevant variables----------------
for ($i = 1; $i <= 3; $i++) // Why do you have 3 here and 8 in the uploading part ?
{
$Image_Upload = "Image_Upload_".$i // Supposing that your upload fields are named "Image_Upload_1" "Image_Upload_2" etc.
$fl = "fl$i";
@$fl[$i]= $_FILES[$Image_Upload]]['name'];
@$fl_Size[$i]= $_FILES[$Image_Upload]['size'];
@$fl_Name[$i]= $_FILES[$Image_Upload]['name'];
@$fl_Temp[$i]= $_FILES[$Image_Upload]['tmp_name'];
}
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}
//---Upload the files if they exist---------------------------------
for ($i = 1; $i <= 8; $i++)
{

if ($fl_Size[$i] < $size and $fl_Size[$i] >0)
{
$uploadFile = "uploads/".$fl_Name[$i];
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file($fl_Temp[$i] , $uploadFile);
chmod($uploadFile, 0644);
$Image_URL[$i] = "../images/uploads/".$fl_Name[$i]; // This is wrong, unless the script resides in ../images
}
}
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");
//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n" // What is $pn ? There is NO $pn definition. $pn should be one of the variables received from the form or hardcoded or included or something like $pn = $fn." ".$ln; OR received through $_GET !!!!!
. "Reply-To: $pea\n"; // There is NO $pea definition. $pea should be $ea !!
$nd_subject = "Upload to the HBRC Website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New File(s):\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Desired Password: $dp\n" // There is NO $dp definition. $dp should be one of the variables received from the form !!!!! Or, received through a $dp = $_GET[dp]; if you are sending it from the form through the GET method !!
. "-------------------------------------------\n";
. "Fees are up to date: $mf\n" ; // There is NO $mf definition. $mf should be one of the variables received from the form !!!!! OR received through $_GET
. "-------------------------------------------\n";
for ($i = 1; $i <= 8; $i++) // Why is $i set to a max of 8 if you only have 3 upload fields ? They should be both 3 or both 8
{
if (@$fl_Size[$i] >0) // There is NO $Image_Upload_Size[$i] !!!
{
$nd_message .= "Link to image $i : $Image_URL[$i] \n"
.= "-------------------------------------------\n";
}
}
$nd_message .= "Date of Submission : $date\n";
. "-------------------------------------------\n";
mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");
?>



<?php
// ---- Customized form script for the HBRC---------------
// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$dp = addslashes($_POST['dp']);
@$ea = addslashes($_POST['ea']);
@$mf = addslashes($_POST['mf']);
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");
//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n" // There is NO $pn definition. $pn should be one of the variables received from the form or hardcoded or included or recieved through $_GET !!!!!
. "Reply-To: $pea\n"; // There is NO $pea definition. $pea should be $ea instead !!!
$nd_subject = "Query from the HBRC website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New Query:\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Desired Password: $dp\n"
. "-------------------------------------------\n"
. "Fees are up to date: $mf\n"
. "-------------------------------------------\n"
$nd_message .= "Date of Submission : $date\n"
. "-------------------------------------------\n";
mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");
?>
-------------------------------------Form 3 -------------------------------
<?php
// ---- Customized form script for the HBRC---------------
// Receiving variables -----------------------------------
@$fn = addslashes($_POST['fn']);
@$ln = addslashes($_POST['ln']);
@$dp = addslashes($_POST['pn']);
@$ea = addslashes($_POST['ea']);
@$mf = addslashes($_POST['cm']);
@$mf = addslashes($_POST['qy']);
//---------------------------------------------------------------
// Find Server date and Time (note server location-HBRC in US)---
$date = date("l jS F Y, g:i A");
//---------Sending Email to form owner ---------------------------
$nd_header = "From: $pn\n"
. "Reply-To: $ea\n";
$nd_subject = "Query from the HBRC website";
$nd_email_to = "eitassignment@hbrc.dwat.co.nz";
$nd_message = "New Query:\n"
. "-------------------------------------------\n"
. "Senders First Name: $fn\n"
. "Senders Last Name: $ln\n"
. "Senders Email Address: $ea\n"
. "Senders Phone Number: $pn\n"
. "-------------------------------------------\n"
. "Query: $qy\n" . "-------------------------------------------\n"
. "Contact Method: $cm\n"
. "-------------------------------------------\n"
$nd_message .= "Date of Submission : $date\n"
. "-------------------------------------------\n";
mail($nd_email_to, $nd_subject ,$nd_message ,$nd_header ) ;
header("Location: thankyou.html");
?>

Watdaflip
06-28-2007, 07:54 PM
When you are listing the images in the email you are just giving links.... the url that you are giving is

$Image_URL[$i] = "../images/uploads/".$fl_Name[$i];

The url of the website is not added to this when it is listed in the email, and even if it was (naval's already commented on this), it isn't going link properly. Using ../ only works when the php script is handling a file on the server.

Also as naval has commented with your inconsistency with the amount of files. Perhaps just make the upload files an array and just use count() to find out how many uploads there are and use that number in the loop instead of a hard-coded number.

abcdme
06-29-2007, 12:10 PM
thank you two very much for your help! I wish i was as good with php as you two are.