Ask about a PHP problem here.
feebot
Posts: 2 Joined: Thu Jun 02, 2011 5:24 pm
Post
by feebot » Thu Jun 02, 2011 5:29 pm
I have posted this on new boston forum as wel as php academy forum and no one can help. here is my entire php code and form on the same page.
<?php
if (isset($_POST['name']) && isset($_POST['email']) && isset ($_POST['company']) && isset($_POST['message']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$company=$_POST['company'];
$message=$_POST['message'];
if (!empty($name) && !empty($email) && !empty($company) && !empty($message))
{
if (strlen($name)>35 || strlen($email)>50 || strlen($company)>50 || strlen($message)>1000)
{echo 'Sorry, maxlength for some fields have been exceeded.';}
else
{
$to='test@test.com ';
$subject = 'Input from Drill-Safe.';
$body = $name."\n".$message;
$headers = 'From: '.$email;
if (@mail($to, $subject, $body, $headers))
{echo 'Thanks for submitting to Drill-Safe.';}
else
{echo 'Sorry, an error has occurred. Please try again later.';}
}
}
else
{echo 'All fields are required.';}
}
?>
<form action="input.php" method="POST">
<label>NAME:<br /></label><input type="text" name="name" size="25" maxlength="35"><br><br>
<label>E-MAIL:<br /></label><input type="text" name="email" size="25" maxlength="50"><br><br>
<label>COMPANY<br /></label><input type="text" name="company" size="25" maxlength="50"><br><br>
<label>COMMENTS or QUESTIONS:<textarea rows="9" name="message" cols="60" maxlength="1000"></textarea></label><br><br>
<input type="submit" value="Send" name="submit">
</form>
I have also tried sending it to another php page, and nothin!
jacek
Site Admin
Posts: 3262 Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:
Post
by jacek » Thu Jun 02, 2011 5:50 pm
You can shorten the isset line to this.
if (isset($_POST['name'], $_POST['email'], $_POST['company'], $_POST['message']))
which means the same thing as what you have.
As for the problem, what message do you get when you click the submit button ? And can you post the full code in one block ?
Dominion
Posts: 32 Joined: Thu May 05, 2011 11:32 pm
Post
by Dominion » Thu Jun 02, 2011 8:54 pm
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<?php
if (isset($_POST['name'],$_POST['email'],$_POST['company'],$_POST['message']))
{
$name=$_POST['name'];
$email=$_POST['email'];
$company=$_POST['company'];
$message=$_POST['message'];
if (!empty($name) && !empty($email) && !empty($company) && !empty($message))
{
if (strlen($name)>35 || strlen($email)>50 || strlen($company)>50 || strlen($message)>1000)
{echo 'Sorry, maxlength for some fields have been exceeded.';}
else
{
$to='test@test.com ';
$subject = 'Input from Drill-Safe.';
$body = $name."\n".$message;
$headers = 'From: '.$email;
if (@mail($to, $subject, $body, $headers))
{echo 'Thanks for submitting to Drill-Safe.';}
else
{echo 'Sorry, an error has occurred. Please try again later.';}
}
}
else
{echo 'All fields are required.';}
}
?>
<form action="" method="POST">
<label>NAME:<br /></label><input type="text" name="name" size="25" maxlength="35"><br><br>
<label>E-MAIL:<br /></label><input type="text" name="email" size="25" maxlength="50"><br><br>
<label>COMPANY<br /></label><input type="text" name="company" size="25" maxlength="50"><br><br>
<label>COMMENTS or QUESTIONS:<textarea rows="9" name="message" cols="60" style ="maxLength:1000"></textarea></label><br><br>
<input type="submit" value="Send" name="submit">
</form>
</body>
</html>
clicking send works fine on wamp...[/quote]
feebot
Posts: 2 Joined: Thu Jun 02, 2011 5:24 pm
Post
by feebot » Fri Jun 03, 2011 3:11 am
Thank you , this finally worked!!! I'm not sure if it would have worked this whole time as well, I put the PHP code into a new php file and it worked, when I put it back into my webpage, the css or html screws it up and it is not visible...weird.
None the less, thank you everyone for the help, my next few projects to accomplish are making a text editor box likr the one i'm typing in right now... or some type of user editable page... or even mebers pages like facebook. If any one has any advice I'd love it!
______________________________________________________________________________________________________________
Last edited by
jacek on Fri Jun 03, 2011 11:17 am, edited 1 time in total.
Reason: Removed unrelated links.