Help with code

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

Post Reply
joreardon
Forum Newbie
Posts: 3
Joined: Thu Jul 02, 2009 4:29 pm

Help with code

Post by joreardon »

Hi all,

I'm a massive newb with php and have built this site for a friend http://www.mileniumhair.co.uk and can not get the appointment page to work:http://www.milleniumhair.co.uk/booking.html

here is what I have cobbled together so far it's probably way OUT!!

Code: Select all

 
<?php
   /* Get the form variables */
    $contact = "jonnyoreardon@yahoo.co.uk";
              $subject = "Hair Appointment at Millennium";
              $title    = stripslashes ($HTTP_POST_VARS['title']);
              $name    = stripslashes ($HTTP_POST_VARS['name']);
              $email   = str_replace(' ','', stripslashes ($HTTP_POST_VARS['email']));
              $day    = stripslashes ($HTTP_POST_VARS['day']);
              $time    = stripslashes ($HTTP_POST_VARS['time']);
              $referredby    = stripslashes ($HTTP_POST_VARS['referred by']);
              $errmsg="";
            if( $HTTP_POST_VARS['action']=="request appointment")
        {
 if(!$HTTP_POST_VARS['name']) 
            {
$errmsg="<b>Please enter your name.</b>";
            }
            elseif(!$HTTP_POST_VARS['email']) 
            {
                    $errmsg="<b>Please enter your tel.</b>";
            }
             else if ($HTTP_POST_VARS['name'] ) 
                {
              /* Create the message to send */
            
              $form_msg = "The following Form was submitted " .
                     "on milleniumhair.co.uk.\n\n";
                $msg .= "title: "            . stripslashes ($HTTP_POST_VARS['title']) . "\n";
                $msg .= "Name: "              . stripslashes ($HTTP_POST_VARS['name']) . "\n";
                $msg .= "Email: "             . stripslashes ($HTTP_POST_VARS['email']) . "\n";
                $msg .= "Day: "             . stripslashes ($HTTP_POST_VARS['day']) . "\n";
                $msg .= "time: "            . stripslashes ($HTTP_POST_VARS['time']) . "\n";
                $msg .= "Enquiry: "             . stripslashes ($HTTP_POST_VARS['enquiry']) . "\n";
            
              /* Compose the message to send to the contact */
              $form_msg .= $msg . "\nThank you for your request.\n";
            
              /* Send it! */
              mail($contact,$subject,$form_msg);
            
              /* Send an email to the form poster confirming receipt of form */
              $done=0;
             
              if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) 
              
                    {  /* checks to see if email is valid */
               
              $ret_subj = "Submission Confirmation";
              $ret_msg .= "Thank you for submitting your appointment request.\n";
              $ret_msg .= "The form details submitted were:\n\n";
              $ret_msg .= $msg . "\nRegards,\webmaster@milleniumhair.co.uk";
              mail ($email, $ret_subj, $ret_msg);
              $done = 1;
              
                    }
                        else     
                            {
                                $errmsg="<b>Please enter a valid email address.</b>";
                            }       
                }       
        }
            ?>
can anyone help me ????? :banghead:
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with code

Post by requinix »

So what's the problem with it?

Forgive me for being lazy and not trying to figure it out myself.
DagasSiren
Forum Newbie
Posts: 4
Joined: Thu Jul 02, 2009 4:12 pm
Location: Warren Indiana USA
Contact:

Re: Help with code

Post by DagasSiren »

looking at the code... (and remember running on only 2 hrs sleep here) :dubious: i don't see anything wrong with the code. it all looks there... what problem are you having?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with code

Post by jackpf »

$HTTP_POST_VARS is waaaaay old. You should use $_POST instead.

What version of PHP are you running?

And yeah, what's the problem? Would be useful...
joreardon
Forum Newbie
Posts: 3
Joined: Thu Jul 02, 2009 4:29 pm

Re: Help with code

Post by joreardon »

Sorry for the late reply,
The information is not sending to my email address and also the 'Thank you for your request' is not showing when posted as well as any of the required fields are not showing notification of a problem. When you hit the request an appointment button on http://www.mileniumhair.co.uk it just clears the fields and dose not submit.

Not sure why, hope this sheds a little light?

J
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Help with code

Post by Eric! »

You probably haven't told your form where to post the data. Can you post your html form here for us to see what you're doing?
joreardon
Forum Newbie
Posts: 3
Joined: Thu Jul 02, 2009 4:29 pm

Re: Help with code

Post by joreardon »

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
 
Design by Rear design
http://www.reardesign.co.uk
For Millenium Hair Studio Shipley Bradford
$contact = "davidwillson007@btinternet.com";
 
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Millennium Hair Studio Shipley</title>
<meta name="keywords" content="Hairdressers, shipley, bradford, hair studio, salon" />
<meta name="description" content="Bradford and shipley hairdressers, extention specialist with award wining stylists" />
<link href="../css/default.css" rel="stylesheet" type="text/css" />
<?php
                                                    
            /* Get the form variables */
              
              $contact = "jonnyoreardon@yahoo.co.uk";
              $subject = "Hair Appointment at Millennium";
              $title    = stripslashes ($HTTP_POST_VARS['title']);
              $name    = stripslashes ($HTTP_POST_VARS['name']);
              $email   = str_replace(' ','', stripslashes ($HTTP_POST_VARS['email']));
              $day    = stripslashes ($HTTP_POST_VARS['day']);
              $time    = stripslashes ($HTTP_POST_VARS['time']);
              $referredby    = stripslashes ($HTTP_POST_VARS['referred by']);
              $errmsg="";
            if( $HTTP_POST_VARS['action']=="request appointment")
        {
            
                 if(!$HTTP_POST_VARS['name']) 
            {
                    $errmsg="<b>Please enter your name.</b>";
            }
            else if(!$HTTP_POST_VARS['email']) 
            {
                    $errmsg="<b>Please enter your tel.</b>";
            }
             else if ($HTTP_POST_VARS['name'] ) 
                {
              /* Create the message to send */
            
              $form_msg = "The following Form was submitted " .
                     "on milleniumhair.co.uk.\n\n";
                $msg .= "title: "            . stripslashes ($HTTP_POST_VARS['title']) . "\n";
                $msg .= "Name: "              . stripslashes ($HTTP_POST_VARS['name']) . "\n";
                $msg .= "Email: "             . stripslashes ($HTTP_POST_VARS['email']) . "\n";
                $msg .= "Day: "             . stripslashes ($HTTP_POST_VARS['day']) . "\n";
                $msg .= "time: "            . stripslashes ($HTTP_POST_VARS['time']) . "\n";
                $msg .= "Enquiry: "             . stripslashes ($HTTP_POST_VARS['enquiry']) . "\n";
            
              /* Compose the message to send to the contact */
              $form_msg .= $msg . "\nThank you for your request.\n";
            
              /* Send it! */
              mail($contact,$subject,$form_msg);
            
              /* Send an email to the form poster confirming receipt of form */
              $done=0;
             
              if (eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) 
              
                    {  /* checks to see if email is valid */
               
              $ret_subj = "Submission Confirmation";
              $ret_msg .= "Thank you for submitting your appointment request.\n";
              $ret_msg .= "The form details submitted were:\n\n";
              $ret_msg .= $msg . "\nRegards,\webmaster@milleniumhair.co.uk";
              mail ($email, $ret_subj, $ret_msg);
              $done = 1;
              
                    }
                        else     
                            {
                                $errmsg="<b>Please enter a valid email address.</b>";
                            }
         
                        
                }
                
                
        }
            
    ?></head>
<body>
<!-- start header shipley hairdressers, hair studio -->
<div id="header">
    <div id="logo">
      <h1><a href="#"><img src="images/MILLENNIUM.png" alt="" /></a></h1>
  </div>
    <div id="menu">
        <ul>
                  <li class="active"><a href="index.html"> home</a></li>
            <li><a href="stylists.html">stylists</a></li>
          <li><a href="salon.html">salon</a></li>
          <li><a href="prices.html">prices</a></li>
          <li><a href="opening.html">opening </a></li>
            <li><a href="contacts.html">contact</a></li>
            <li><a href="booking.html">appointment</a></li>
      </ul>
  </div>
</div>
<!-- end header shipley hairdressers, hair studio -->
<!-- start page shipley hairdressers, hair studio -->
<div id="page">
    <!-- start content shipley hairdressers, hair studio  -->
    <div id="content">
        <div class="post"><a name="form"></a>
          <div id="forms"> 
  <p>&nbsp;</p>
  <p>To request an appointment at our salon based in Shipley, please fill out the details below and <br />
    we will respond as soon as possible.</p>
  <form method="post" action="booking.php#form">
  <input type="hidden" name="formid" value="AppointmentFormID" class="hidden" />
    <fieldset>
    <legend> Your details
    </legend>
    <label for="title"> <br />
    Title
    <select id="title" name="title" >
      <option value="Mr.">Mr.</option>
 
      <option value="Mrs.">Mrs.</option>
      <option value="Ms.">Ms.</option>
      <option value="Miss.">Miss</option>
      <option value="Dr.">Dr.</option>
    </select>
    </label>
    <label accesskey="n" for="name" class="first"><br />
    <br />
    Your Name
          <input id="name" name="name" type="text" maxlength="60"  />
 
    </label>
    <label for="telephone"> <br />
    <br />
    Telephone Number
    <input id="telephone" name="telephone" type="text" maxlength="25"  />
    </label>
    <label accesskey="e" for="email"> <br />
    <br />
    Your email address
    <input type="text" name="email" id="email" maxlength="40"  />
    </label>
    <label for="day"> <br />
    <br />
    Preferred Day
    <select id="day" name="day" >
 
        <option value="">---SELECT---</option>
      <option value="Monday">Monday</option>
      <option value="Tuesday">Tuesday</option>
      <option value="Wednesday">Wednesday</option>
      <option value="Thursday">Thursday</option>
      <option value="Friday">Friday</option>
 
      <option value="Saturday">Saturday</option>
    </select>
    </label>
    <label for="time"> <br />
    <br />
    Preferred Time
    <select id="time" name="time" >
        <option value="">---SELECT---</option>
      <option value="Morning">Morning</option>
 
      <option value="Afternoon">Afternoon</option>
    </select>
    </label>
    <label for="refferedby"> <br />
    <br />
    Where did you hear about us?
    <select id="referredby" name="referredby" >
        <option value="">---SELECT---</option>
        <option value="Search Engine">Search Engine</option>
 
      <option value="Yell.com">Yell.com</option>
      <option value="Shop Front">Shop Front</option>
      <option value="Evening Press">Evening Press</option>
      <option value="Friend">Friend</option>
      <option value="Other">Other</option>
    </select>
 
    </label>
    <label accesskey="c" for="comments"> <br />
    <br />
    Notes
    <br />
    <textarea name="comments" id="comments" ></textarea>
    </label>
    <p>&nbsp;</p>
    <div class="clearer"></div>
    </fieldset>
    <fieldset>
    <legend></legend>
 
    <div class="clearer"></div>
    </fieldset>
    <input class="submit" type="submit" value="Request Appointment" />
  </form>
</div>  
<div class="entry"></div>
           </div>
  </div>
    <div id="sidebarabout">
    
    </div>
<!-- end sidebar shipley hairdressers, hair studio -->
    <div style="clear: both;"></div>
<!-- end page shipley hairdressers, hair studio -->
<!-- start footer shipley hairdressers, hair studio -->
<div id="footer">
    <p id="legal">(c) 2008 millennium. Design by <a href="http://www.reardesign.co.uk/"> REAR design</a>.</p>
</div>
</div>
<!-- end footer shipley hairdressers, hair studio -->
</body>
</html>
Hope this makes it clearer!
cheers
j
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with code

Post by jackpf »

You can't just do if($var) unless it's a bool or something; you have to use isset().
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with code

Post by requinix »

jackpf wrote:You can't just do if($var) unless it's a bool or something; you have to use isset().
If it weren't for the "unless it's a bool or something" I'd agree with you. But because you said that I don't know exactly what you're referring to.

if ($var) is perfectly valid for variables that exist. If they don't exist, PHP issues a warning and assumes the variable is null - that's when you should be using isset or empty: to check if a variable exists.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Help with code

Post by jackpf »

Well, it's not the way you're supposed to do it.

Code: Select all

if($_GET['something'])
{
//this will trigger an e_warning if $_GET['something'] does not exist
}
Or you could just do it how everyone else does it an use isset().

And anyway, you're always displaying your form, so it's obviously going to show the form every time.
Post Reply