SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Nov 2003
    Location
    Sydney
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy simple php form help

    Hi All,
    I have built a form to be sent by php.
    It works on my server but not on my client's....
    Form is at www.cbdfinancial.com.au/website/contact.php

    It is giving me the following error -
    "Undefined variable: name in C:\Inetpub\cbd\website\contact.php on line 46"

    This is what I have used. I am no expert with php!


    <?php
    if($name!="")
    {

    $comment ="
    Name: $name
    Company: $company
    Company ABN: $ABN
    Contact Number: $contactArea $contactNumber
    Fax Number: $faxArea $fax
    Email: $email
    Enquiry: $enquiry";

    require("class.libmail.php");
    $mail = new Mail();
    $mail->To("assist@cbdfinancial.com.au ");
    $mail->From("$name");
    $mail->Subject("Contact CBD Insurance");
    $mail->Body($comment);
    $mail->BuildMail();
    $mail->Send();
    echo(" <br>Thank you. <br>We will be in touch shortly.");
    }
    else
    {
    ?>

    <form name="Contact CBD" onsubmit="return validateData(this)" method="post" action="<?=$_SERVER['PHP_SELF']?>">
    <input type=hidden name="recipient" value="assist@cbdfinancial.com.au" alt="Contact CBD Insurance">
    <input type=hidden name="subject" value="client information">
    <input type=hidden name="redirect" value="#">
    <table cellpadding="0" cellspacing="0" border="0" class="text">
    <tr>
    <td width="120">Your Name</td>
    <td><input type="text" name="name" class="forms" size="30"></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td width="120">Company Name</td>
    <td><input type="text" name="company" class="forms" size="30"></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td width="120">Company ABN</td>
    <td><input type="text" name="ABN" class="forms" size="30"></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td width="120">Your Contact Number</td>
    <td><input type="text" name="contactArea" class="forms" size="4"> <input type="text" name="contactNumber" class="forms" size="25"></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td valign="top" width="120">Your Fax Number</td>
    <td valign="top"><input type="text" name="faxArea" class="forms" size="4"><input type="text" name="fax" class="forms" size="25"></td>
    </tr>
    <tr>
    <td valign="top" width="120"></td>
    <td valign="top"><span class="note">please provide area code if applicable</span></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td width="120">Your Email Address</td>
    <td><input type="text" name="email" class="forms" size="30"></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td valign="top" width="120">Your Enquiry</td>
    <td valign="top"><textarea name="enquiry" class="forms" rows="4" cols="28"></textarea></td>
    </tr>
    <tr height="10">
    <td colspan="2" height="10">&nbsp; </td>
    </tr>
    <tr>
    <td width="120"></td>
    <td><span class="note">Please read our <a href="privacy.php">privacy policy</a> and our <a href="disclosure.php">disclosure</a></span></td>
    </tr>
    <tr>
    <td width="120"></td>
    <td><button class="button" name="submit" value="Submit" type="submit" onclick="MM_validateForm('contactNumber','','R','name','','R');return document.MM_returnValue">Submit</button></td>
    </tr>
    </table>
    </form>

    <?php
    }
    ?>

    Can anyone suggest why the form is not working?

    Thanks.

  2. #2
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change
    $name
    to $_PSOT['name']

    and the error is because, your client's server has "register_globals" turned off.(WHICH IS GOOD)

    and get in the habit of using them. in newer version they off by default.

    so, all the variables (say form post) are available with $_POST['var_name']
    all the variables in url are available through $_GET['var_name']
    all the variables in session can be accessed through $_SESSION['var_name']

    IN YOUR CASE
    $comment should be $_POST['comment']
    $name = $_POST['name'] etc.etc.
    ---------------------------
    Errors = Improved Programming.
    My Site

  3. #3
    SitePoint Member
    Join Date
    Nov 2003
    Location
    Sydney
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks but....

    Thanks for the super quick response.
    I have changed the php code (see below) but now am getting the following error...

    "Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\cbd\website\contact.php on line 50"

    Have I missed something? Obviously!


    <?php
    if($_PSOT['name'])
    {

    $_POST['comment'] ="
    Name: $_POST['name']
    Company: $_POST['company']
    Company ABN: $_POST['ABN']
    Contact Number: $_POST['contactArea'] $_POST['contactNumber']
    Fax Number: $_POST['faxArea'] $_POST['fax']
    Email: $_POST['email']
    Enquiry: $_POST['enquiry'];

    require("class.libmail.php");
    $mail = new Mail();
    $mail->To("assist@cbdfinancial.com.au ");
    $mail->From("$_POST['name']");
    $mail->Subject("Contact CBD Insurance");
    $mail->Body($comment);
    $mail->BuildMail();
    $mail->Send();
    echo(" <br>Thank you. <br>We will be in touch shortly.");
    }
    else
    {
    ?>

  4. #4
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wait a minute. you are not supposed to CHANGE ALL THE VARIABLES. just the ones which you receive fromthe form
    PHP Code:
    $comment ="
    Name: 
    $_POST[name]
    Company: 
    $_POST[company]
    Company ABN: 
    $_POST[ABN]
    Contact Number: 
    $_POST[contactArea] $_POST[contactNumber]
    Fax Number: 
    $_POST[faxArea] $_POST[fax]
    Email: 
    $_POST[email]
    Enquiry: 
    $_POST[enquiry]"
    ok now note i din't put quote in the keys.
    so
    $_POST[name]
    SHOULD be
    $_POST['name'] IF AND ONLY IF you wanna use it outside the quotes.
    if you wanna use it inside quotes(like int he code above), you don't need to put quote

    NOTE: the very first line in the if
    it SHOULD BE $_POST
    NOT
    $_PSOT

    hope this helps
    ---------------------------
    Errors = Improved Programming.
    My Site

  5. #5
    SitePoint Member
    Join Date
    Nov 2003
    Location
    Sydney
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok - I must really suck...still getting an error -
    "Notice: Undefined index: name in C:\Inetpub\cbd\website\contact.php on line 46". Am I close!?

    <?php
    if($_POST['name'])
    {

    $comment ="
    Name: $_POST[name]
    Company: $_POST[company]
    Company ABN: $_POST[ABN]
    Contact Number: $_POST[contactArea] $_POST[contactNumber]
    Fax Number: $_POST[faxArea] $_POST[fax]
    Email: $_POST[email]
    Enquiry: $_POST[enquiry]";

    require("class.libmail.php");
    $mail = new Mail();
    $mail->To("assist@cbdfinancial.com.au ");
    $mail->From($name);
    $mail->Subject("Contact CBD Insurance");
    $mail->Body($comment);
    $mail->BuildMail();
    $mail->Send();
    echo(" <br>Thank you. <br>We will be in touch shortly.");
    }
    else
    {
    ?>

  6. #6
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should not say
    if($_POST['name'])

    YOU SHOULD SAY
    if(isset($_POST['name']))

    and before doing that i would always do

    if($_SERVER['REQUEST_METHOD']=='POST')
    {
    //NOW START DOING HERE ALL THE CODE THAT YOU WANT TO DO
    if(isset($_POST['name']))
    {
    //DO THIS BLAH BLAH BLAH
    }
    }
    ---------------------------
    Errors = Improved Programming.
    My Site

  7. #7
    SitePoint Member
    Join Date
    Nov 2003
    Location
    Sydney
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Thank you - very helpful.
    How do I give you a rap - is there a rating for this forum?

  8. #8
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to help you

    For rep:
    You click on this image under the user's name on the left side.
    ---------------------------
    Errors = Improved Programming.
    My Site


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •