PDA

View Full Version : could someone please check my scripting for PHP



urbaneve
August 22nd, 2003, 07:54 AM
this is my first PHP and i was wondering if someone would comment on if this is right or not.


<?PHP
$to = "proimageresumes@yahoo.com";
$subject = "Referal Program"
$header = "From: $name <$email>";

$msg = "$name1\n\n";
$msg .= "$email1\n\n";
$msg .= "$phone1\n\n";
$msg .= "$contact1\n\n";
$msg .= "$email1\n\n";
$msg .= "$name2\n\n";
$msg .= "$email2\n\n";
$msg .= "$phone2\n\n";
$msg .= "$contact2\n\n";
$msg .= "$email2'1\n\n";
$msg .= "$comments\n\n";


mail($to, $subject, $header, $msg, "From: $name\nReply-To: $email\n");
?>
i have noticed that some people have the subject and header at the end of the script -- does this make a difference? can i leave it at the top?

then on my time line i have this code inserted

stop();
Selection.setFocus(nameSpot);


and then for my submit button i have this:

on (release) {
if (name1 eq "" or phone1 eq "" or email1 eq "" or
contact1 eq "" or comments eq "" or name2 eq "" or phone2 eq "" or email2 eq"" or contact2 eq "")
{
stop ();
}
else
{
loadVariablesNum ("referal.php", 0, "POST");
gotoAndStop (2);
}
}


now do i need to add anything into my main html page for PHP or will this do it?

thanks guys

Freddythunder
August 22nd, 2003, 04:23 PM
Looks fine to me - have you tried it? Don't forget a semicolon after $subject = "Referal Program" in your PHP script. You'd get a parse error otherwise. And, no, nothing has to be in your HTML with the flash movie to have it work.

You may also want to add this to the beginning of your php file:

$name=$_POST["name"];
$email=$_POST["email"];
$name1=$_Post["name1"];
//etc..etc..for all your variables comming in

urbaneve
August 22nd, 2003, 05:34 PM
no -- ihavent had a chance to test it yet, my host doesnt support PHP -- so i am looking for a new one, i just wanted to have it ready.

okay i made the changes -- did i get it right (i wasnt sure what you meant by putting at the start of my PHP


<?PHP


$name=$_POST["name"];
$email1=$_POST["email1"];
$phone1=$_POST["phone1"];
$contact1=$_POST["contact1"];
$name2=$_POST["name2"];
$email2=$_POST["email2"];
$phone2=$_POST["phone2"];
$contact2=$_POST["contact2"];
$comments=$_POST["comments"];


$to = "proimageresumes@yahoo.com";
$subject = "Referal Program";
$header = "From: $name <$email>";

$msg = "$name1\n\n";
$msg .= "$email1\n\n";
$msg .= "$phone1\n\n";
$msg .= "$contact1\n\n";

$msg .= "$name2\n\n";
$msg .= "$email2\n\n";
$msg .= "$phone2\n\n";
$msg .= "$contact2\n\n";

$msg .= "$comments\n\n";


mail($to, $subject, $header, $msg, "From: $name\nReply-To: $email\n");
?>

i separated them so i didnt confuse myself by mis-typing something *snirt*

Freddythunder
August 22nd, 2003, 06:05 PM
where does the var $email come from? If it's posted it needs to be in that list in the beginning. Other than that, it looks good.

I don't know about your email command. I thought that the order went like:


mail($to, $subject, $message, $header);

I don't know what that other thing would do. I double checked with this:
http://www.kirupaforum.com/forums/showthread.php?s=&threadid=17604&highlight=PHP+tutorial

urbaneve
August 22nd, 2003, 11:58 PM
which $email var are you talking about.

this one:
1.
$header = "From: $name <$email>";

or this one:

2.
mail($to, $subject, $msg, $header, "From: $name\nReply-To: $email\n");



my thinking was that it was the person sending it to me -- but i do kinda see what you are talking about -- i just dont know how to fix it.



p.s. whadaya know -- i just made member status -- waaaaaahooooo! i am movin up in the world.

urbaneve
August 23rd, 2003, 01:10 AM
okay --- i think i know what you are talking about.

does the 'mail(to.....' need to be the same as the header

in otherwords


$header = "From: $name <$email>";
mail($to, $subject, $msg, $header, "From: $name <$email>");
?>

rather than what i had before


$header = "From: $name <$email>";
mail($to, $subject, $msg, $header, "From: $name\nReply-To: $email\n");

Freddythunder
August 23rd, 2003, 04:49 PM
First off, congrats on your new status - you'll make a fine member :P

Secondly, the only way you are going to know who fills out your form by email address is for them to actually fill out a box with their email address. It's not possible for anything to read someone's email address from a browser. Therefore, it needs to be treated like any other variable coming in to the PHP script from Flash...and I was talking about both of them because they would be empty variables when you ran the script.

For your last thing, I think I mentioned it before, but I don't know if that added line would do anything in the mail command. I have always just used:


mail($to, $subject, $msg, $header);

However, I think we may have cleared that up seeing that you aren't going to know who it's from automatically!! :P

eyezberg
August 23rd, 2003, 06:28 PM
also:
$name=$_POST["name"];
versus
$msg = "$name1\n\n";
=>either name, or name1 ...

If you want to start PHP, cool, it's not hard, very much like Actionscript...but you'll get lots of errors for stupid typos & missing semicolons and have to be very carefull with variable names, coz they are case-sensitive in PHP (myvar != Myvar) !!

urbaneve
August 24th, 2003, 06:16 AM
you are most definately right about typos and such -- on the first lines of each (name and name1) they were both supposed to be name1 (i just forgot to add it in)

and you answered another question of mine. case sensitivity. thanks

but i redid it and used name and candidate (it is a referal form they are filling out so it has to be 2 different names listed.)

urbaneve
September 5th, 2003, 03:46 PM
okay -- i am still having problems with this. i am not receiving any response in my email.

im not sure what the problem is -- i posted my script and everyone said it looked fine, so i must be missing something somewhere along the way. could someone help me out on this before i pull all of my hair out. >>>urbaneve needs an icon with its hair being pulled out<<<

and do i need to add " $result= " to the "mail" line-

(like this --- $result=mail($to, $subject, $msg, $header, "From: $name <$email>");

--or-- did i have right to begin with
(like this --- mail($to, $subject, $header, $msg, "From: $name\nReply-To: $email\n"); )

thanks

Freddythunder
September 5th, 2003, 05:04 PM
I could be wrong, but that last part of the command for mail should just say "From: $name <$email>". I don't think PHP would understand that... Look here for more info:

http://www.php.net/manual/en/ref.mail.php

On the bottom of that page, someone has 'from' as another header like:


$headers['Subject'] = 'Your subject';
$headers['From'] = 'user1@your.domain.com';
//then the command:
$result=mail($to, $subject, $headers, $msg);


Does that help?

Freddythunder
September 5th, 2003, 05:22 PM
BTW - here's that smiley you've been looking for - I made it when I was doing that login thing a while back:
http://freddythunder.com/test/hair.gif

urbaneve
September 7th, 2003, 06:54 AM
youve got my vote darlin

(ps -- thanks for the little dude - he will get much use)

urbaneve
September 7th, 2003, 07:11 AM
no -- it didnt work

but -- i wonder

even though i have the php file in the same directory as the the index file, i dont have any URL dircection to the order.php --- do i need to include that somewhere in the scripting? otherwise how does the submit button know where to locate the order.php file?

it knows where to send the varibles but how does it know where to load them from when it only says

on (release) {
if (name eq "" or address eq "" or city eq "" or state eq "" or zip eq "" or phone eq "" or contact eq "" or email eq "" or services eq "" or payment_method eq"" or cardnumber eq"" or exp eq"" or comments eq"")
{
stop ();
}
else
{
loadVariablesNum ("order.php", 0, "POST");
gotoAndStop (2);
}
}

Freddythunder
September 8th, 2003, 02:05 AM
It depends if you are expecting something in return from that. I think you have to load the variables going to the script, and then ask it again for a responce; preferably in an onEnterFrame thing because sometimes it takes a while.

Also, in the AS that you have, why not do something like:


if (name && address && city && state && zip && phone && contact && email && services && payment_method && cardnumber && exp && comments){
loadVariablesNum ("order.php", 0, "POST");
gotoAndStop (2);
} else {
gotoAndStop(1);
_root.message._visible = true
//being a message saying to complete all fields
}

I'm an optimist, so I program that way.

By the looks of it, you're doing an ecommerce thing. That is secure, right? If not, second guess what you're doing. Those kind of things are easier to hack than you think....:sigh:

All in all. If your PHP file is in the same directory as your Flash movie talking to it - it will work. Good luck!!

felipegm
September 24th, 2003, 01:52 PM
Hi everybody

My form is working fine.
The last thing I´d like to take a closer look is the message.
Is you press return (enter) on the message field on the form, the message text doesn´t come with new lines. It comes with all closer with one another.

I´d like something like this from the message field:

Hi
My name is Felipe.
I study at blah blah blah.

But I´m getting this:
HiMy name is Felipe.I study at blah blah blah.

Any help????

felipegm
September 24th, 2003, 03:00 PM
I was looking at the PHP scritps and have questions:

what is this for???

\n\n
\r\n
.=

thanks

Freddythunder
September 24th, 2003, 03:38 PM
'\n' is the same thing as <br> in HTML. It's just like hitting a return. So, there's your answer from the above thing, you just have to add some of those.

'\r'...I don't remember....sorry. :sigh:

'.=' is a continuation of a string on a different line for one variable. For instance, this is ripped out of a guest book script that talks to MySQL:


$query = "INSERT INTO guests ";
$query .= "(guest_id, guest_name, ";
$query .= "guest_email, guest_time, guest_message) ";
$query .= " values(0000,'$name','$email',NULL,'$message')";

You don't necessarily need to join a string like that, you could just make one big long line, but this seems easier for me. Basically, it just means:


$query="(guest_id, guest..........'$message')";

Hope that clears up some things :)

felipegm
September 24th, 2003, 03:41 PM
thanks Freddy for your help.

I´m just wondering why my script is not working...
I´m using \n on the message variable, but the text comes to my email in one big block.