PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
truepal20032001
Forum Commoner
Posts: 27 Joined: Mon Jun 25, 2007 8:28 pm
Post
by truepal20032001 » Tue Jul 03, 2007 3:00 am
no matter if i insert everything correcty, it will still give me the negative result, what's wrong?...
Code: Select all
<div align="center">
<h1><strong></p>
</div>
<div align="center">
<div align="center">
<div align="center">
<meta http-equiv="refresh" content="2;url=/home.html">
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$msg = "Name: $_POST[name]\n";
$msg.= "Email: $_POST[email]\n";
$msg.= "Phone: $_POST[phone]\n";
$msg.= "Comment/Message:\n";
$msg.= "$_POST[comment]\n<br><br>";
$msg.= "Message recieved: ".date('H:i, jS F');
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > ){
@mail('my@mail.com','Comment/Message',$msg,'FROM:'.$_POST[email]);
echo "Thankyou! You'll be replied soon.</strong></h1>
<p><strong><br />
</strong><br />
<strong></strong></p>
<p>";
echo '<html><h1 align="center"><img src="info/check.jpg"</html>';
}
else{
echo "ERROR!!</strong></h1>
<p><strong>An error has just occured, these might have been the cause: <br />
1. Did not fill in all of the neccessary blanks.</strong><br />
<strong>2.Invalid Information<br>3.Comment is less that 8 characters long.</strong></p>
<p>";
echo '<html><h1 align="center"><img src="info/error.jpg" width="433" height="133"/></html>';
}
?>
every input result:
Code: Select all
ERROR!!
An error has just occured, these might have been the cause:
1. Did not fill in all of the neccessary blanks.
2.Invalid Information<br>3.Comment is less that 8 characters long.
Rovas
Forum Contributor
Posts: 272 Joined: Mon Aug 21, 2006 7:09 am
Location: Romania
Post
by Rovas » Tue Jul 03, 2007 3:10 am
You had to use
Code: Select all
<?php
if (!isset ($_POST[name]) && !isset($_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
//the rest
}
else
{
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > ){// your code}
}
?>
Now it should work.
truepal20032001
Forum Commoner
Posts: 27 Joined: Mon Jun 25, 2007 8:28 pm
Post
by truepal20032001 » Tue Jul 03, 2007 3:22 am
it still does not work...
i believe the problem is
Code: Select all
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > ), but don't know what's wrong,
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Tue Jul 03, 2007 3:26 am
Please post the values of your variables.
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Tue Jul 03, 2007 3:53 am
Code: Select all
<?php
$name = 'Joe';
$email = 'Joe@hoody.com';
$comment = 'This is a simple comment';
if ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > )
{
echo 'Yahoo';
}
else
{
echo 'Oh...';
}
?>
Works perfect. Are you sure you have these values right before your if statement if your script?
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Jul 03, 2007 12:23 pm
Echo the values you are comparing just before the conditional so you can see what PHP is seeing.
truepal20032001
Forum Commoner
Posts: 27 Joined: Mon Jun 25, 2007 8:28 pm
Post
by truepal20032001 » Tue Jul 03, 2007 2:35 pm
well you see that is what i am assuming because that is what i put in the contact form and then it is converted to this:
Code: Select all
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$name = 'joe';
$email = 'email@somewhere.com';
$comment = 'comment here';
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Tue Jul 03, 2007 3:01 pm
It will take less then a minute to verify... Just do it.
Code: Select all
echo "Debug start<br/>";
echo $name.' '.$email.' '.$comment.'<br/>';
echo "Debug finish<br/>";
if ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > )
// The rest of your code
Last edited by
Gente on Tue Jul 03, 2007 3:01 pm, edited 1 time in total.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Jul 03, 2007 3:01 pm
truepal20032001 wrote: well you see that is what i am assuming ...
I didn't ask you to assume, I asked you to...
Everah wrote: Echo the values you are comparing just before the conditional so you can see what PHP is seeing.
That is the only way to see what PHP is seeing. Please do that and report back.
truepal20032001
Forum Commoner
Posts: 27 Joined: Mon Jun 25, 2007 8:28 pm
Post
by truepal20032001 » Tue Jul 03, 2007 3:42 pm
and that is weird, cause i checked the for and everything checks out..., here is html form:
Code: Select all
<td width="84%" rowspan="5" align="left" valign="top"><form name="form1" method="post" action="contact.php">
<span class="style20"><span class="style21">
<input name="name" type="text" id="name">
<input name="email" type="text" id="email">
<input name="phone" type="text" id="phone">
</span></span>
<span class="style20"><span class="style21">
<textarea name="comment" cols="45" rows="6" wrap="on" id="comment"></textarea>
<input type="submit" name="Submit" value="Submit">
</span></span>
</form>
and ofcource the action:
contact.php
Code: Select all
<div align="center">
<h1><strong></p>
</div>
<div align="center">
<div align="center">
<div align="center">
<?php
function error(){
echo "ERROR!!</strong></h1>
<p><strong>An error has just occured, these might have been the cause: <br />
1. Did not fill in all of the neccessary blanks.</strong><br />
<strong>2.Invalid Information<br>3.Comment is less that 8 characters
long.</strong></p>
<p>";
echo '<html><h1 align="center"><img src="info/error.jpg" width="433"
height="133"/></html>';
}
if (!isset ($_POST[name]) && !isset($_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$msg = "Name: $_POST[name]\n";
$msg.= "Email: $_POST[email]\n";
$msg.= "Phone: $_POST[phone]\n";
$msg.= "Comment/Message:\n";
$msg.= "$_POST[comment]\n<br><br>";
$msg.= "Message recieved: ".date('H:i, jS F');
}
echo "Debug start<br/>";
echo "$name". "$email". "$comment"."<br/>";
echo "Debug finish<br/>";
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen
($comment) > ){
@mail('truepal20032001@yahoo.com','Comment/Message',$msg,'FROM:'.$_POST
[email]);
echo "Thankyou! You'll be replied soon.</strong></h1>
<p><strong><br />
</strong><br />
<strong></strong></p>
<p>";
echo '<html><h1 align="center"><img src="info/check.jpg"</html>';
}
else{
error();
}
?>
i am sorry if iam tiring you with this code
Gente
Forum Contributor
Posts: 252 Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:
Post
by Gente » Tue Jul 03, 2007 3:53 pm
Are you joking???
Look at your code! Here:
Code: Select all
if (!isset ($_POST[name]) && !isset($_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
// Yo will never reach this part!!! Because of YOUR CONDITION
}
Your initial post was without this statement
truepal20032001
Forum Commoner
Posts: 27 Joined: Mon Jun 25, 2007 8:28 pm
Post
by truepal20032001 » Tue Jul 03, 2007 4:01 pm
Rovas wrote: You had to use
Code: Select all
<?php
if (!isset ($_POST['name']) && !isset($_POST['email']))
{
$name = $_POST['name'];
$email = $_POST['email'];
//the rest
}
else
{
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > ){// your code}
}
?>
Now it should work.
but that is what they told me to put, if before that it still didn't work that is why i said that this might be the problem,
Code: Select all
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > 8))
it will still not work if i fix it like this:
Rovas wrote: You had to use
Code: Select all
<?php
if (!isset ($_POST['name']) && !isset($_POST['email']))
{
error();
}
else
{ $name = $_POST['name'];
$comment = $_POST['comment'];
$email = $_POST['email'];
If ((strlen($name) > 1) && (strlen($email) > 1) && (strstr($email,'@')) && (strlen($comment) > ){// your code}
}
?>
Now it should work.
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Tue Jul 03, 2007 4:23 pm
Code: Select all
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$comment = $_POST['comment'];
?>
If there is no post array then these will all be null (which is another way of saying empty, not set, null).
You also need to check if they are set.
Code: Select all
<?php
if ($_SERVER['REQUEST_METHOD'] == 'post' && !empty($_POST))
{
// You now have a post array that is not empty.
// Set some vars and handle your business
}
else
{
// There was no post.
// Do what you do when there is no form posted.
}
?>