Results 1 to 8 of 8

Thread: Embeding PHP into HTML

  1. #1
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Embeding PHP into HTML

    I'm trying to embed a contact php script into my website and it shows some of the php code on the html site...

    Here is the script
    Code:
    <?php 
    $name = $_POST['name']; 
    $sub = $_POST['sub']; 
    $address = $_POST['email']; 
    $msg = $_POST['msg']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $mess = "
    Subject: $sub \n 
    Message: $msg \n 
    From: $address \n 
    IP: $ip \n 
    "; 
    if ( (!$name)||(!$sub)||(!$msg) ){ 
    echo "Please fix the following:<BR>"; 
    
    
    if(!$name){ 
    echo "Please fill in your name<BR>"; 
    } 
    
    if(!$sub){ 
    echo "Please fill in the subject<BR>"; 
    } 
    if(!$msg){ 
    echo "Please fill in the message<BR><BR>"; 
    } 
    echo(' 
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form>'); 
    } else { 
    
    mail("kandflawncare@gmail.com", "Subject: $sub", $mess, "From: $name <$address>"); 
    if(mail) { 
    echo "Thank you! Please wait up to 24 hours for a reply."; 
    } else { 
    echo "The message could not be sent. Please try again later."; 
    } 
    } 
    ?>
    and here is a link to the page that I'm trying to embed it in with the problem shown on the page.
    http://kandflawncare.funurl.com/contact.html

    and this is a page with just the php script

    http://kandflawncare.funurl.com/contact.php

    Any help would be greatly taken.....


    Thanks,
    K&F Lawn Care

  2. #2
    Join Date
    Jan 2008
    Posts
    73
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    simply replace each of the double qouats inside the echo to single

    for example:
    echo("
    <form action='contact.php' method='post'>

    you confuse the parser with the " inside the string to echo so it echo until the first " he sees

  3. #3
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    please clarify what you mean...... I don't quite understand what you are saying.

  4. #4
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    he is saying to switch all your double quotes ( " ) inside the echo to single quotes ( ' ), and when you begin the echo use a double quote instead so:

    echo " <form action='contact.php' ... "

    etc etc.

    hopefully that clears it up for you

  5. #5
    Join Date
    Jan 2008
    Posts
    73
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    exactly what moshmbi said.this is what i meant.
    if you still for some reason prefer to use double quotes ( " ) inside ECHO then you need to use escape char: \
    so it will be something like:
    echo " <form action=\"contact.php\" ... "

  6. #6
    Join Date
    Oct 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok I have changed it to look like this

    Code:
    <?php 
    $name = $_POST['name']; 
    $sub = $_POST['sub']; 
    $address = $_POST['email']; 
    $msg = $_POST['msg']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $mess = '
    Subject: $sub \n 
    Message: $msg \n 
    From: $address \n 
    IP: $ip \n 
    '; 
    if ( (!$name)||(!$sub)||(!$msg) ){ 
    echo 'Please fix the following:<BR>'; 
    }
    if(!$name){ 
    echo 'Please fill in your name<BR>'; 
    } 
    if(!$sub){ 
    echo 'Please fill in the subject<BR>'; 
    } 
    if(!$msg){ 
    echo 'Please fill in the message<BR><BR>'; 
    } 
    echo(' 
    <form action="contact.php" method="post"> 
    Name: <input type="text" name="name" class="input"><BR> 
    Subject: <input type="text" name="sub" class="input"><BR> 
    
    E-mail <input type="text" name="email" class="input"><BR> 
    Message: 
    <textarea name="msg" rows="7" cols="50" class="input"></textarea> 
    <input type="submit" value="Send" class="button"> 
    </form>'); 
    else { 
    mail('kandflawncare@gmail.com', 'Subject: $sub', $mess, 'From: $name <$address>'); 
    if(mail) { 
    echo 'Thank you! Please wait up to 24 hours for a reply.'; 
    } else { 
    echo 'The message could not be sent. Please try again later.'; 
    } 
    }
    ?>
    I have also moved the location that I'm using the form on to here...

    http://designdt.co.cc/book/contact.html

    and I'm still getting some code showing up on the page

    the only place that there are " are in the HTML that makes up the form. other wise I have replaced them with '

  7. #7
    Join Date
    Jan 2008
    Posts
    73
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default

    Code:
    <?php 
    $name = $_POST['name']; 
    $sub = $_POST['sub']; 
    $address = $_POST['email']; 
    $msg = $_POST['msg']; 
    $ip = $_SERVER['REMOTE_ADDR']; 
    $mess = "
    Subject: $sub \n 
    Message: $msg \n 
    From: $address \n 
    IP: $ip \n 
    "; 
    if ( (!$name)||(!$sub)||(!$msg) ){ 
    echo "Please fix the following:<BR>"; 
    }
    if(!$name){ 
    echo "Please fill in your name<BR>"; 
    } 
    if(!$sub){ 
    echo "Please fill in the subject<BR>"; 
    } 
    if(!$msg){ 
    echo "Please fill in the message<BR><BR>"; 
    } 
    echo("
    <form action='contact.php' method='post'> 
    Name: <input type='text' name='name' class='input'><BR> 
    Subject: <input type='text' name='sub' class='input'><BR> 
    
    E-mail <input type='text' name='email' class='input'><BR> 
    Message: 
    <textarea name='msg' rows='7' cols='50' class='input'></textarea> 
    <input type='submit' value='Send' class='button'> 
    </form>"); 
    else { 
    mail('kandflawncare@gmail.com', 'Subject: $sub', $mess, 'From: $name <$address>'); 
    if(mail) { 
    echo "Thank you! Please wait up to 24 hours for a reply."; 
    } else { 
    echo "The message could not be sent. Please try again later."; 
    } 
    }
    ?>
    again:
    echo goes with double quotes (") everything inside use single quotes or \"

    so if you want to echo company "abc" u can:

    echo "company 'abc' ";

    or

    echo "company \"abc\"";

  8. #8
    Join Date
    Oct 2008
    Location
    Columbia Md
    Posts
    27
    Thanks
    1
    Thanked 8 Times in 8 Posts

    Lightbulb

    Hello, looking at the code php is set to echo, I recommend that you keep it consistent to your DOCTYPE. At the address you provided it is marked as xhtml strict. The <BR> break you use does not meet the xhtml standard. I would use <br />. This would help ensure the page validates if you run it through a html validator.

    Ben

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
  •