/    Sign up×
Community /Pin to ProfileBookmark

Amateur php question

I’ve got this code

[code=php]<!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 = “[email protected]”;
$subject = “Web Order”;

$body = “The following confirms the details of your order:n”;
$body .= “nn”;
$body .= “Name: ” . $Name . “n”;
$body .= “Email: ” . $Email . “n”;
$body .= “Company: ” . $Company . “n”;
$body .= “nn”;
$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>
[/code]

It gives out this error

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

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

Thanks! ?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@shane_carrAug 19.2007 — What generated an error statement like that?

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

[code=php]$body .= "HR 1001 Widgets: (" . $qtyA . " * ) "n";
$body .= "HR 1002 Widgets: (" . $qtyB . " * ) "n";
$body .= "HR 1003 Widgets: (" . $qtyC . " * ) "n";[/code]


they should be

[code=php]$body .= "HR 1001 Widgets: (" . $qtyA . " * ) n";
$body .= "HR 1002 Widgets: (" . $qtyB . " * ) n";
$body .= "HR 1003 Widgets: (" . $qtyC . " * ) n";[/code]
Copy linkTweet thisAlerts:
@CloudskyauthorAug 19.2007 — 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.

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

The problem seems to be this.
Copy linkTweet thisAlerts:
@shane_carrAug 19.2007 — Your code looks fine, but try replacing this:

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


I don't know about this, but you could also try removing all of the n's.
Copy linkTweet thisAlerts:
@CloudskyauthorAug 19.2007 — 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!
Copy linkTweet thisAlerts:
@aussie_girlAug 19.2007 — try changing these echo "<br>n";

to just "n";

you shouldn't need a break and a new line
×

Success!

Help @Cloudsky 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.6,
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,
)...