Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have written a HTML and PHP code which should show a survey form and invite you to enter your email address and have a submit button for you to click. However, when I "run" the code, I get some gibberish which I wrote in my code, which I did not expect to appear on my survey form. The code that I have written is as follows:
session_start();
if (!empty($_POST['posted']) && !empty($_POST['email'])){
$folder = "surveys/" . strtolower($_POST['email']);
// send path information to the session
$_SESSION['folder'] = $folder;
if(!file_exists($folder)) {
// make the directory and then add the empty files
mkdir($folder, 0777, true);
}
header("Location: 08_6.php");
}
else { ?>
<html>
<head>
<title>Files and folders - Online Survey</title>
</head>
<body bgcolor="white" text="black">
<h2>Survey Form</h2>
<p>Please enter your email address to start recording your comments</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="1">
<p>Email address: <input type="text" name="email" size="45" /><br />
<input type="submit" name="submit" value="Submit"></p>
</form>
</body>
</html>
<?php }
What's happening is that I'm getting:
session_start(); if (!empty($_POST['posted']) && !empty($_POST['email'])){...
and whole bunch of other stuff appearing at the top of the webpage, which is certainly not what I want. Could one of you experts please tell me what I'm doing wrong?
You have not included an opening <?php tag in your page.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I want to access HTML data in the PHP file to add two numbers. Below is the HTML code to take user input-
addnumber.html
<html>
<head>
</head>
<body>
<form action="add.php" method="POST">
<input type="number" name="fno"/>
<input type="number" name="sno"/>
<input type="submit"/>
</form>
</body>
</html>
Below id the add.php file code
<?php
$a = $POST['fno'];
$b = $POST['sno'];
$ans = $a+$b;
echo $ans;
?>
But after clicking the submit button in the chrome PHP code is shown instead of the result of two number addition.
Is the file code not running because I need to use localhost:8080 instead of localhost. Please help if possible.
Note: I can run PHP using http://localhost:8080/programs/add.php line.
I changed the port from 80 to 8080 for Apache and it works.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am new to php and I'm trying to have a form in which you have to input two numbers which are added to each other when submitted.
It works just fine, but whenever I click submit it opens a new tab in my browser (tested in chrome and firefox) to show to anwser, which I don't want.
I write the php code in the same file as my html.
Can anyone help me?
Thank you!
<!DOCTYPE html>
<form target="/index.php" method="GET">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit">
</form>
<p>anwser:</p>
<?php
echo $_GET["num1"] + $_GET["num2"];
?>
php has nothing to do with new window or not...
its your target what does it... it opens a new window with internal name "/index.php"
what you are looking for is action="/index.php"
<form action="/index.php" method="GET">
<input type="number" name="num1">
<input type="number" name="num2">
<input type="submit">
</form>
<p>anwser:</p>
<?php
echo $_GET["num1"] + $_GET["num2"];
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
Unfortunately all of my PHP commands showing on page as HTML, I don't know why. I had to use it before without errors though. What is my mistake here?
..........................................................................................................................................................................................................................................................................................................................................
<html>
<head>
<title>Add items system</title>
<?php
if (isset($_POST['submit']))
{
if(isset($_POST['yes']))
{
file_put_contents('ak47content.html', '<li class="li1"><img src="images/'.$_POST["image"].'.png"><span><b>Available:</b> <br>'.$_POST['available'].'<br><br><img src="images/hiks.png"><br> </span></li>' . "\r\n", FILE_APPEND);
}
else
{
if(isset($_POST['no']))
{
file_put_contents('ak47content.html', '<li class="li1"><img src="images/'.$_POST['image'].'.png"><span><b>Available:</b> <br>'.$_POST['available'].'<br><br><img src="images/hiks.png"><br> </span></li>' . "\r\n", FILE_APPEND);
}
else
{
echo "Please specify if it's available or not!";
}
}
}
?>
</head>
<body>
<form action="add.php" method="post" name="all">
<b>Available:</b> <input type="radio" name="yes" value="male">Yes <input type="radio" name="no" value="male">No <br>
<b>If NOT available, so when:</b>
<select name="available">
<option>Soon</option>
<option>Next week</option>
<option>Next month</option>
<option>Next year</option>
</select><br>
<b>Exteriors:</b> <select name="exterior">
<option>Battle-Scarred</option>
<option>Factory New</option>
<option>Minimal Wear, Battle-Scarred</option>
<option>Field-Tested, Battle-Scarred</option>
<option>Factory New, Field-Tested</option>
</select><br>
<b>Image name:</b> <input type="text" name="image"><br>
<input type="submit" value="Add" name="submit">
</form>
</body>
</html>
It's not interpreted as PHP, check if PHP is up and running!
- check the file extension
- make sure that php is integrated correctly with your server
- try to reinstall xampp
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
When I click in my newsletter subscribe button in my footer Im going to the top of my page.
I can have my sucess message my error messages but Im going always to the top of my page. And I dont want this because I want that usre see the feedback message without scroll down to my footer.
Do you see why this happening and how can I fix this?
<form action="" name="newsletter" method="post" enctype="multipart/form-data">
<div id="email_newsletter_container">
<input type="text" id="email" value="<?php if(isset($_POST['email'])) echo $email; ?>" name="email" placeholder="Insert your email..." required/>
<input type="hidden" name="newsl_sub" value="subscribe" />
<button class="btnn" type="submit" name="subscribe"><span>Subscribe</span></button>
</div>
</form>
When you put action="" the action will reload the page. If you put action="#newsletter" it should take the user to the section of the page that contains the form when the form is submitted. You may also want to add id="newsletter" to the form to ensure compatibilities.
<? if($post_was_submitted_and_comment_was_inserted) { ?>
<script>
window.addEventListener("load", function(){
document.getElementById("comments").scrollIntoView();
});
</script>
<? } ?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am new to html & php and I appreciate your help. I am trying to accept user input into a webpage and then after the user clicks the submit button, write a new record out to MySQL. I am using Wordpress so the tags are not exactly textbook.
So my first problem is that the submit button does not appear to execute the php code. I also would appreciate it if someone could check how I am passing my html field names to the php variables to make sure that I am on the right track. Thanks for your help!
html code to collect user input for fields on the form.....
<?php>
if(isset($_POST['Submit'])) {
$FName = $_POST['FName'];
$MI = $_POST['MI'];
$LName = $_POST['LName'];
....
?>
<form action="" method="post">
<input type="submit" name="Submit" value="Submit">
I think it can be good to read a bit more about it. Check here.
Anyway, you need to say the name of the file to post to: <input type="submit" action="file.php" name="Submit" /> for example.
And you need to have more inputs than the submit.
Acording to your php you should have as example this in the html:
<form action="your_php_file.php" method="post">
<p>Your first name: <input type="text" name="FName" /></p>
<p>Your last name: <input type="text" name="LName" /></p>
<p>Your MI: <input type="text" name="MI" /></p>
<p><input type="submit" name="Submit"/></p>
</form>
And the php tags are like <?php to open, and ?> to close.
So like:
<?php
if(isset($_POST['Submit'])) {
$FName = $_POST['FName'];
$MI = $_POST['MI'];
$LName = $_POST['LName'];
//....
?>
Your PHP tags are incorrect. Use <?php and ?> to tell PHP to start and stop interpreting the code between them. Also, make sure you're closing the form element (I only see you're opening it) using </form> and that you indeed have all those fields contained inside of it.