system
March 17, 2011, 12:00pm
1
Hi, could someone tell me why this code:
<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for="name">Name: </label>
<input type="text" name="name" value="<?php echo htmlentities($name) ?>
<label for="email">Email: </label>
<input type="text" name="email" value="<?php echo htmlentities($visitor_email) ?>">
<label for="message">Message:</label>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message) ?></textarea>
Is displaying PHP code in the name, email and message areas of the form ? Is there a location that the PHP file be placed, I’ve tried a few methods nothing works.
system
March 17, 2011, 12:50pm
2
It’s not your code… probably a server configuration issue.
Try adding this line above the form:
<?php phpinfo(); ?>
And show us the results…
<?php
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$visitor_email=$_POST['email'];
$user_message=$_POST['message'];
}
?>
<form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for="name">Name: </label>
<input type="text" name="name" value="<?php echo htmlentities(@$name) ?>">
<label for="email">Email: </label>
<input type="text" name="email" value="<?php echo htmlentities(@$visitor_email) ?>">
<label for="message">Message:</label>
<textarea name="message" rows=8 cols=30><?php echo htmlentities(@$user_message) ?></textarea>
<input type="submit" name="submit">
</form>
Note:::
Here ‘@’ suppresses the notices like,
at first time loading the form, this php variables are not initialized…
system
March 17, 2011, 1:16pm
4
I tried both of your code before the form begins, same results
You try only this code;
<?php phpinfo(); ?>
system
March 17, 2011, 1:47pm
6
What’s the name of your file? Is it something.php ? You may not have PHP installed on your server.
Mandes
March 17, 2011, 3:03pm
7
I disagree Transio
Each PHP statement must close with a semicolon.
And the HTML is wrong on the first input in the form , theres no closing speech mark or closing > to the input tag,
system
March 17, 2011, 11:25pm
8
transio - I tried that code same thing. There is a PHP file. Mandes what are you referring too ?
Mandes
March 17, 2011, 11:36pm
9
Your code
<DIV style="TEXT-ALIGN: left" dir=ltr><form method="POST" name="contact_form" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for="name">Name: </label>
<input type="text" name="name" value="<?php echo htmlentities($name); ?>" >
<label for="email">Email: </label>
<input type="text" name="email" value="<?php echo htmlentities($visitor_email); ?>">
<label for="message">Message</label>
<textarea name="message" rows=8 cols=30><?php echo htmlentities($user_message); ?></textarea>
<DIV>
system
March 18, 2011, 12:19am
10
What I meant was ‘what part of the code’ I realize it was my code <g>
Edit: What is wrong ?
Mandes
March 18, 2011, 12:31am
11
As I said earlier, your PHP statements werent followed by a semicolon ‘;’
And you had HTML errors (no closing tag or speech mark on the first input)
The code I posted in post #9 was CORRECTED so just copy and paste
system
March 18, 2011, 12:45am
12
Your code, mangles my page up. I copied the following code but that doesn’t work either:
<form method=“POST” name=“contact_form” action=“<?php echo htmlentities($_SERVER[‘PHP_SELF’]); ?>”>
<label for=“name”>Name: </label>
<input type=“text” name=“name” value=“<?php echo htmlentities($name); ?>” >
<label for=“email”>Email: </label>
<input type=“text” name=“email” value=“<?php echo htmlentities($visitor_email); ?>”>
<label for=“message”>Message</label>
<textarea name=“message” rows=8 cols=30><?php echo htmlentities($user_message); ?></textarea>
Mandes
March 18, 2011, 5:53am
13
Then you have problems in other parts of your code too !!
Fixing these problems has had a chain effect on other errors.
system
March 18, 2011, 11:50am
14
The form was working, the problem was and still is that PHP code is showing up in the form input fields.
Fixing these problems has had a chain effect on other errors.
This is exactly why I asked the question, what is wrong with the form and what needs to be fixed.
What is the name of the file that contains form and php code?
system
March 18, 2011, 12:06pm
16
html-contact-form.php
captcha_code_file.php
I hope this is what you’re asking ?
Mandes
March 18, 2011, 12:49pm
17
The form was working, the problem was and still is that PHP code is showing up in the form input fields.
This is exactly why I asked the question, what is wrong with the form and what needs to be fixed.
Your first code was wrong, I fixed it for you, if that highlights other problems your going to have to post all the code so we can see where the other problems may lay.
Let’s first find out why the php commands aren’t parsed and executed. Even with the semicolumns missing, that would result in an error, not the entire php commands displayed in the html page.
Mandes
March 18, 2011, 1:21pm
20
agreed
But id be suprised if this is the only PHP in the entire script, so in that case all that code would be displaying too.
@SiberianHuskey
put this following code into a file called test.php, then run it, tell us the result.
<p>this is html</p>
<?php
echo 'this is php';
?>