Click to See Complete Forum and Search --> : Amateur php question


Cloudsky
08-19-2007, 02:13 AM
I've got this code

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<?

print_r($_POST);

//make sure there is data in the name and email fields
if( empty($_POST["Name"]) )
{
$error["name"] = "Name is required.";
$Name = "";
}
else
$Name = $_POST["Name"];

if( empty($_POST["Email"]) )
{
$error["email"] = "Email is required.";
$Email = "";
}
else
$Email = $_POST["Email"];

if( empty($_POST["Company"]) )
{
$Company = "";
}
else
$OtherInfo = $_POST["Company"];

if( empty($_POST["PhoneNo"]) )
{
$OtherInfo = "";
}
else
$OtherInfo = $_POST["PhoneNo"];

//check to make sure the qty fields are whole numbers
//but only check if there was data entered
if( !empty($_POST["qtyA"]) )
{
if( is_numeric($_POST["qtyA"]) && ( intval($_POST["qtyA"]) == floatval($_POST["qtyA"]) ) )
{
//we have a whole number
}
else
$error["qtyA"] = "Please enter a whole number for Quantity 1001.";
}

if( !empty($_POST["qtyB"]) )
{
if( is_numeric($_POST["qtyB"]) && ( intval($_POST["qtyB"]) == floatval($_POST["qtyB"]) ) )
{
//we have a whole number
}
else
$error["qtyB"] = "Please enter a whole number for Quantity 1002.";
}

if( !empty($_POST["qtyC"]) )
{
if( is_numeric($_POST["qtyC"]) && ( intval($_POST["qtyC"]) == floatval($_POST["qtyC"]) ) )
{
//we have a whole number
}
else
$error["qtyC"] = "Please enter a whole number for Quantity 1003.";
}


//we should have at least 1 item ordered in the form
if( empty($_POST["qtyA"]) && empty($_POST["qtyB"]) && empty($_POST["qtyC"]) )
$error["no_qty"] = "Please enter at least 1 item to order.";


if( is_array($error) )
{

echo "An error occurred while processing your order.";
echo "<br>\n";
echo "Please check the following error messages carefully, then click back in your browser.";
echo "<br>\n";

while(list($key, $val) = each($error))
{
echo $val;
echo "<br>\n";
}

//stop everything as we have errors and should not continue
exit();

}
$mailto = "yonlh@singnet.com.sg";
$subject = "Web Order";

$body = "The following confirms the details of your order:\n";
$body .= "\n\n";
$body .= "Name: " . $Name . "\n";
$body .= "Email: " . $Email . "\n";
$body .= "Company: " . $Company . "\n";
$body .= "\n\n";
$body .= "HR 1001 Widgets: (" . $qtyA . " * ) "\n";
$body .= "HR 1002 Widgets: (" . $qtyB . " * ) "\n";
$body .= "HR 1003 Widgets: (" . $qtyC . " * ) "\n";
$body .= "\n";


mail($mailto, $subject, $body);
mail($Email, $subject, $body);

echo "The following information was sent.";
echo "<br>\n";
echo "<pre>\n";
echo $body;
echo "</pre>\n";*/
?>
</body>
</html>


It gives out this error

http://img.photobucket.com/albums/v326/Cloudsky/Error.jpg

Even after commenting out the affected areas and saving my work. I still recieve these errors. Can anyone help me out here?

Thanks! :)

shane.carr
08-19-2007, 02:28 AM
What generated an error statement like that?

If you pasted your code word-for-word, your problem is in these 3 lines:

$body .= "HR 1001 Widgets: (" . $qtyA . " * ) "n";
$body .= "HR 1002 Widgets: (" . $qtyB . " * ) "\n";
$body .= "HR 1003 Widgets: (" . $qtyC . " * ) "n";

they should be

$body .= "HR 1001 Widgets: (" . $qtyA . " * ) \n";
$body .= "HR 1002 Widgets: (" . $qtyB . " * ) \n";
$body .= "HR 1003 Widgets: (" . $qtyC . " * ) \n";

Cloudsky
08-19-2007, 02:53 AM
Hi, I have already made the changes but it still gives out the same problem. I'm not sure what the problem is, i grabbed this code from another site and only changed the naming conventions of some of the attributes.

http://img.photobucket.com/albums/v326/Cloudsky/Erro2.jpg

The problem seems to be this.

shane.carr
08-19-2007, 03:03 AM
Your code looks fine, but try replacing this:

while(list($key, $val) = each($error))
//to
foreach($error as $key => $val)

I don't know about this, but you could also try removing all of the \n's.

Cloudsky
08-19-2007, 03:38 AM
Thanks for the replies.

However, the problem is, the program don't seem to register the changes. Whoops ignore the image on the 2nd post

Thanks!

aussie girl
08-19-2007, 07:22 AM
try changing these echo "<br>\n";
to just "\n";
you shouldn't need a break and a new line