PDA

View Full Version : Embeding PHP into HTML



highalpine
10-01-2008, 08:54 PM
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


<?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

genia
10-05-2008, 08:47 PM
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

highalpine
10-06-2008, 04:09 AM
please clarify what you mean...... I don't quite understand what you are saying.

Moshambi
10-06-2008, 04:22 AM
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

genia
10-06-2008, 08:26 AM
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\" ... "

highalpine
10-08-2008, 11:17 PM
ok I have changed it to look like this



<?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 '

genia
10-09-2008, 11:29 AM
<?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\"";

olveyphotodesign
10-09-2008, 01:58 PM
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