Reply LinkBack Thread Tools Search this Thread
Old 16-12-2007, 15:39   #1 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Can Someone Help me with my PHP script

Hey. I have the following script. Which is suppost to validate the information in the textboxes and send error messages if something is wrong. I didnt make the validation too complex, but I just wanted to start it. And after everything is validated, it should send all the information to my email.

PHP Code:
<form method="post" name="msgform" id="msgform">

<?php

$errmsg          
''
$fname             ''
$lname             ''
$saddress         ''
$city             ''
$country         ''
$pcode             ''
$email             ''
$htelephone         ''
$ftelephone         ''
$company         ''
$companyp         ''
$rci             ''
$typecard         ''
$ccard             ''
$edate             ''
$ncard             ''
$cardaddress         ''
$cardcity         ''
$cardcountry         ''
$cardpc         ''
$cardtelephone         ''
$password         ''
$confirmpass         ''
$agree             ''

if(isset(
$_POST['send']))
{
    
$fname   $_POST['fname'];
    
$lname   $_POST['lname'];
    
$saddress $_POST['saddress'];
    
$city $_POST['city'];
    
$country   $_POST['country'];
    
$email   $_POST['email'];
    
$htelephone $_POST['htelephone'];
    
$ftelephone $_POST['ftelephone'];
    
$companyp   $_POST['companyp'];
    
$typecard  $_POST['typecard '];
    
$ccard   $_POST['ccard'];
    
$edate $_POST['edate'];
    
$ncard   $_POST['ncard'];
    
$cardaddress   $_POST['cardaddress'];
    
$cardcity   $_POST['cardcity'];
    
$cardcountry   $_POST['cardcountry'];
    
$cardpc   $_POST['cardpc'];
    
$cardtelephone   $_POST['cardtelephone'];
    
$password $_POST['password'];
    
$confirmpass $_POST['confirmpass'];
    
$agree $_POST['agree'];
    
    
    if(
trim($fname) == '') {
        
$errmsg 'Please enter your first name';
    } 
    else if(
trim($lname) == '') {
        
$errmsg 'Please enter your last name';
    }
    else if(
trim($saddress) == '') {
        
$errmsg 'Please enter your address';
    } 
    else if(
trim($city) == '') {
        
$errmsg 'Please enter your city';
    } 
    else if(
trim($country) == '') {
        
$errmsg 'Please enter your country';
    } 
    else if(
trim($email) == '') {
        
$errmsg 'Please enter your e-mail address';
    }
    else if(!
isEmail($email)) {
        
$errmsg 'Please enter your valid e-mail address';
    }
    else if(
trim($htelephone) == '') {
        
$errmsg 'Please enter home phone';
    }
    else if(
trim($edate) == '') {
        
$errmsg 'Please enter the expiry date of the card you entered';
    }
    else if(
trim($ncard) == '') {
        
$errmsg 'Please enter the name on the card you entered';
    }
    else if(
trim($password) == '') {
        
$errmsg 'please chose a password for your account';
    }
    else if(
trim($aconfirmpass) == '') {
        
$errmsg 'Please confirm you the password you have entered';
    }
    else if(
trim($agree) == '') {
        
$errmsg 'You must agree to our Terms and Conditions';
    }
    if(
$errmsg == '')
    {
        if(
get_magic_quotes_gpc()) {
            
$subject stripslashes($subject);
            
$message stripslashes($message);
        }    
        
    
$to      "myemail@hotmail.com";
        
$subject Order for Starter Plan;
        
$msg     "First name: $fname\r\nLast name: $lname\r\nAddress: $saddress\r\nCity: $city\r\nCountry: $country\r\nPostal Code: $pcode\r\nEmail: $email\r\nHome Telephone: $htelephone\r\nFax Telephone: $ftelephone\r\nCompany: $company\r\nReferal Customer ID: $rci\r\nType of card: $typacard\r\nCredit Card #: $ccard\r\nName on Card: $ncard\r\nCard Address: $cardaddress\r\nCard City: $cardcity\r\nCard Country: $cardcountry\r\nCard Postal Code: $cardpc\r\nCard Telephone: $cardtelephone\r\nPassword: $password\r\nConfirm Password: $confirmpass\r\n";

        
        
mail($to$subject$msg"From:$fname\r\n");
?>
<div align="center" class="errmsg">Thank You. Your request has been sent!</div>

<?php } } if(!isset($_POST['send']) || $errmsg != '') { ?>
<?php 
if(!empty($errmsg)) { echo "<div align=\"center\" class=\"errmsg\">" $errmsg "</div>"; } ?>




    <div id="middle">
        <div id="maininfo">
                <div id="Plan">
                    <div id="Plantop" class="style3">Your Plan</div>
                    <div id="Planbottom">
                        <div id="orderform3">
                            <div class="style2" id="formtitles">Your Plan of Choice:<div class="style9">Starter Plan <span class="style13">$2.98</span><span class="style14">/Month</span></div></div>
                        </div>
                    </div>
                </div>
                <div id="Address">
                    <div id="Addresstop" class="style3">User Information</div>
                    <div id="Addressbottom">
                        <div id="orderform">
                            <div id="formleft">
                                <div class="style2">*First Name:</div><div id="textfields"><input name="fname" type="text" id="fname" maxlength="200" size="30" class="style6" value="<?=$fname;?>"></div>
                                <div class="style2">*Last Name:</div><div id="textfields"><input name="lname" type="text" id="lname" maxlength="200" size="30" class="style6" value="<?=$lname;?>"></div>
                                <div class="style2">*Street Address:</div><div id="textfields"><input name="saddress" type="text" id="saddress" maxlength="200" size="30" class="style6" value="<?=$saddress;?>"></div>
                                <div class="style2">*City:</div><div id="textfields"><input name="city" type="text" id="city" maxlength="200" size="30" class="style6" value="<?=$city;?>"></div>
                                <div class="style2">*Country:</div><div id="textfields"><input name="country" type="text" id="country" maxlength="200" size="30" class="style6" value="<?=$country;?>"></div>
                            </div>
                            <div id="formright">
                                <div class="style2">*Postal Code:</div><div id="textfields"><input name="pcode" type="text" id="pcode" maxlength="200" size="30" class="style6" value="<?=$pcode;?>"></div>
                                <div class="style2">*Email:</div><div id="textfields"><input name="email" type="text" id="email" maxlength="200" size="30" class="style6" value="<?=$email;?>"></div>
                                <div class="style2">*Home Telephone:</div><div id="textfields"><input name="htelephone" type="text" id="htelephone" maxlength="200" size="30" class="style6" value="<?=$htelephone;?>"></div>
                                <div class="style2">Fax Telephone:</div><div id="textfields"><input name="ftelephone" type="text" id="ftelephone" maxlength="200" size="30" class="style6" value="<?=$ftelephone;?>"></div>
                            </div>
                        </div>
                        <div id="orderform2">
                            <div id="formleft">
                                <div class="style6">Are you a business owner? Please enter your business information into the following:</div>
                                <div class="style2">Company:</div><div id="textfields"><input name="company" type="text" id="company" maxlength="200" size="30" class="style6" value="<?=$company;?>"></div>
                                <div class="style2">Company Telephone:</div><div id="textfields"><input name="companyp" type="text" id="companyp" maxlength="200" size="30" class="style6" value="<?=$companyp;?>"></div><img src="../image/icon/bluepost.gif">
                            </div>
                        </div>
                    </div>
                </div> 
                <div id="Affiliatecode">
                    <div id="Affiliatecodetop" class="style3">Affiliate Referal</div>
                    <div id="Affiliatecodebottom">
                        <div id="orderform">
                            <div id="formright">
                                <div class="style2">Referal Customer ID:</div><div id="textfields"><input name="rci" type="text" id="rci" maxlength="200" size="30" class="style6" value="<?=$rci;?>"></div>
                            </div>
                            <div id="formleft">
                                <div class="style6">Did a current member of something.com refer you to our service(s)? Input their customer ID into the following:</div>
                            </div>
                        </div>
                        <div id="orderform2"> 
                            <div id="formleft"><img src="../image/icon/blueperson.gif"></div>
                        </div>
                    </div>
                </div> 
                <div id="Credit">
                    <div id="Credittop" class="style3">Credit Card Information</div>
                    <div id="Creditbottom">
                        <div id="orderform">
                            <div id="formleft">
                                <div class="style2">*Credit Card Type:</div><div id="textfields"><input name="typecard" type="text" id="typecard" maxlength="200" size="30" class="style6" value="<?=$typecard;?>"></div>
                                <div class="style2">*Credit Card Number:</div><div id="textfields"><input name="ccard" type="text" id="ccard" maxlength="200" size="30" class="style6" value="<?=$ccard;?>"></div>
                                <div class="style2">*Expiry Date:</div><div id="textfields"><input name="edate" type="text" id="edate" maxlength="200" size="30" class="style6" value="<?=$edate;?>"></div>
                                <div class="style2">*Name on Card (First and Last):</div><div id="textfields"><input name="ncard" type="text" id="ncard" maxlength="200" size="30" class="style6" value="<?=$ncard;?>"></div>
                            </div>
                            <div id="formright">
                                <div class="style6">If your user information is different from the information on your credit card, please fill in the following:</div>
                                <div class="style2">Address:</div><div id="textfields"><input name="cardaddress" type="text" id="cardaddress" maxlength="200" size="30" class="style6" value="<?=$cardaddress;?>"></div>
                                <div class="style2">City:</div><div id="textfields"><input name="cardcity" type="text" id="cardcity" maxlength="200" size="30" class="style6" value="<?=$email;?>"></div>
                                <div class="style2">Country:</div><div id="textfields"><input name="cardcountry" type="text" id="cardcountry" maxlength="200" size="30" class="style6" value="<?=$htelephone;?>"></div>
                                <div class="style2">Postal Code:</div><div id="textfields"><input name="cardpc" type="text" id="cardpc" maxlength="200" size="30" class="style6" value="<?=$ftelephone;?>"></div>
                                <div class="style2">Telephone:</div><div id="textfields"><input name="cardtelephone" type="text" id="cardtelephone" maxlength="200" size="30" class="style6" value="<?=$ftelephone;?>"></div>
                            </div>
                        </div>
                        <div id="orderform2"> 
                            <div id="formleftcredit" class="style6"></div> 
                        </div> 
                    </div>
                </div> 
                <div id="Userinfo">
                    <div id="Userinfotop" class="style3">User Information</div>
                    <div id="Userinfobottom">
                        <div id="orderform">
                            <div id="formright">
                                <div class="style2">*Chose a Password:</div><div id="textfields"><input name="password" type="text" id="password" maxlength="200" size="30" class="style6" value="<?=$password;?>"></div>
                                <div class="style2">*Confirm Password:</div><div id="textfields"><input name="confirmpass" type="text" id="confirmpass" maxlength="200" size="30" class="style6" value="<?=$confirmpass;?>"></div>
                            </div>
                            <div id="formleft">
                                <div class="style6">Chose a password that would will remember. This password will be used to access something.com. Do not share this information for security reasons.</div>
                            </div>
                        </div>
                        <div id="orderform2"> 
                            <div id="formleft"><img src="../image/icon/bluekey.gif"></div>
                        </div>
                    </div>
                </div>
                <div id="Submit">
                    <div id="Submittop" class="style3">Agreement and Submit</div>
                    <div id="Submitbottom">
                        <div id="orderform5">
                            <div class="style2"><input name="agree" type="radio" id="agree" value="">*Agree to all <a href="../legal/terms.html" class="orangetext">Terms and Conditions</a></div></br>
                             <input name="send" type="submit" class="button" id="send" value="Submit Order" onclick="return checkForm();">
                        </div>
                    </div>
                </div>

</form>
            
<?php } function isEmail($email) { return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email)); } ?>

Can someone tell me what is wrong? it doesnt seem to work! and could someone tell me what excess code I have. And useless stuff I added which doesnt need to be there. Any help to make this php script work and to make i better is appriciated! thanks!

Last edited by Maciek : 16-12-2007 at 15:55.
  Reply With Quote
Old 16-12-2007, 15:45   #2 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
I have a radio button for "agree"... maybe thats the problem. How do you validate a radio button?!! soo that might be the error!
  Reply With Quote
Old 16-12-2007, 15:53   #3 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
its a Parse error soo i must be missing a ; or ).
  Reply With Quote
Old 16-12-2007, 15:56   #4 (permalink)
ahref
Registered User
 
ahref's Avatar
 
Join Date: Dec 2007
Posts: 20
what line does the parse error occur on?
  Reply With Quote
Old 16-12-2007, 16:11   #5 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
OHHHH jeeeze. I found it!!! im a stupid newbe and ya, i never figured out that it told me where the error was! SORRY. it was on like 295. which turned out to be the section with the "$subject: something plan". I got it! thanks.
  Reply With Quote
Old 16-12-2007, 16:14   #6 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
while we're talking about my stupiditiy. Can you explain to me what this function does:

PHP Code:
if(get_magic_quotes_gpc()) {
            
$subject stripslashes($subject);
            
$message stripslashes($message);
    } 
  Reply With Quote
Old 16-12-2007, 16:26   #7 (permalink)
ahref
Registered User
 
ahref's Avatar
 
Join Date: Dec 2007
Posts: 20
it strips slashes from the subject and message if magic quotes is on

example from php.net

PHP Code:
<?php
$str 
"Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>
  Reply With Quote
Old 16-12-2007, 17:56   #8 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
ohh ok. NOW. ive ran into a problem with my script. I try to move the success message to another place and it totally screws with my whole website layout. its annoying. The error message when moved reacts fine with everything. But its stupid that everything is php and the sucess message is in a div? so it has to be in between the code its in or else it wont work. Is there a php way for making a success message for my form? so that i can place it anywhere and it will work fine. thanks..
  Reply With Quote
Old 16-12-2007, 18:18   #9 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
Parsing issues aside, your form isn't going to work for one major reason - you didnt put action="something.php" in the initial <form> tag, so the form will have no idea where to go with the information when you push the submit button.
  Reply With Quote
Old 16-12-2007, 18:25   #10 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
whats this "something" in something.php ?
  Reply With Quote
Old 16-12-2007, 18:26   #11 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
As for your last question there, I think you have to realize what exactly php does.

Php looks at the current set of circumstances (which could include anything - location of user, time of day, information entered into form, information in database and any number of other things), and then runs through a script using that information to basically create a text file that it sends to that browser. You could really make the text file anything, but since we are working with browsers, and browsers interpret (x)html, we usually make php output (x)html. So when you ask if there is a php solution to outputting a success answer instead of html, that doesnt really make sense, as what php does IS output html. If you output anything else, your browser can't interpret it.

If the output is causing troubles with your design, then you need to learn more about design to be able to fix it. Php is great for what it does, but unless you know what exactly the (x)html is that you want to output, then knowing php isn't really going to do much for you. Its like putting the cart before the horse.

So maybe you should take a bit of time to learn some basic (x)html and css first before php. Thats really probably the better order in which to do it, unless you have someone telling you what (x)html they want you to output.
  Reply With Quote
Old 16-12-2007, 18:28   #12 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
"something.php" was just an example. You have to put the filename that contains the script you want to run. It looks like you have everything contained in one file, so it should probably be the filename of the file you are working in. If your script was in a different file from the form, you would want to use that filename instead.
  Reply With Quote
Old 16-12-2007, 18:33   #13 (permalink)
ahref
Registered User
 
ahref's Avatar
 
Join Date: Dec 2007
Posts: 20
its the address you send the mail to essentially
  Reply With Quote
Old 16-12-2007, 18:33   #14 (permalink)
Maciek
I like Iced Tea
 
Maciek's Avatar
 
Join Date: Nov 2007
Location: Kitchener.Ontario.Canada
Posts: 93
Send a message via MSN to Maciek
Umm ya, I know my css and html. I designed my whole site with css. and I used this php on other pages and it worked fine. Its just this bugger that not working out for me. It should be contained in a box but it goes and does its own thing.
  Reply With Quote
Old 16-12-2007, 18:37   #15 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
I'm sorry to tell you, but you do not know html very well at all. That is an absolute mess of divs.
And if you knew CSS well, then your error message wouldn't be a problem, because you would just fix the issue using some CSS positioning.
  Reply With Quote
Old 16-12-2007, 18:38   #16 (permalink)
Shiro
shiro
 
Shiro's Avatar
 
Join Date: Aug 2007
Location: Yokohama, Japan
Posts: 2,606
Finally, when in doubt, look at the source code for the page you have outputted, and see if it is ok. If you have errors That may help with your error issue.
  Reply With Quote