Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I used this below code in www.codeacademy.com online php editor. It doesnt print my desired output. Please show me where I have made mistake
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form action="index.php" method="POST">
<input type= "text" name="num">
<input type="submit" name="submit">
</form>
<p>
<?php
if(isset($_POST['submit']))
{
$type=$_POST['num'];
echo "$type";
}
?>
</p>
</body>
</html>
Try echo $type instead of echo "$type";
If it doesn't work then replace action="index.php" to action = ""
I tested it on my apache server , working just fine. just store the code in index.php and call it with http:// not file://
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 needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to edit php files from the admin panel. How can I do this? I've seen this in CMS like wordpress and joomla. Is there a php library or something?
I recommend Ace for that purpose. It is a code editor built in Javascript: https://ace.c9.io/
To read the files in and save them after editing, you can use built in PHP functions like file_get_contents() and file_put_contents().
Here is a minimal working example:
<?php
if (isset($_POST['code'])) {
file_put_contents('myfile.php', $_POST['code']);
}
$code = htmlentities(file_get_contents('myfile.php'));
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.3.0/ace.js"></script>
</head>
<body>
<form action="" method="post">
<textarea id="source" name="code" autocomplete="off" style="display: none"><?=$code?></textarea>
<div id="editor" style="min-height: 250px"><?=$code?></div>
<input type="submit" />
</form>
<script>
var tarea = document.getElementById('source');
var code = tarea.value;
var editor = ace.edit("editor");
editor.session.setValue(code);
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/php");
editor.getSession().on('change', function(){
tarea.value = editor.getSession().getValue();
});
</script>
</body>
</html>
Important: Set the correct permissions for the files you want to edit.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
There is a href tag:
Send
or a button (needs form tag)
<form action="file.php" method="GET">
<button type="submit">Send</button>
</form>
that will redirect to file.php URL.
I want to send id parameter to another PHP file. How do I do that?
==========================================================================
To send that data where must be provided input params (ex. hidden input) or in-url parameter.
ex.
<form action="file.php" method="GET">
<button type="submit">Send</button>
<input type="hidden" name="id" value="YOUR_ID"
</form>
or
Send
You want to transfer the id only to the next file? Use this in the first:
link_to_2
or
<form...>
<input name="id" type="hidden" value="1">
<button type="submit">btn_to_2</button>
</form>
And in your second file use this for both cases:
<?= $_REQUEST['id'] ?>
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.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
i have a problem, i will send a POST with PHP but i will
send a GET Parameter with the form value:
<form action="/Eventsuche/" method="post">
<table>
<tr>
<td>
<input id="Headsucheort" name="Headsucheort" type="text" value="" />
</td>
<td>
<button type="submit" name="Submit" id="Headsuchestart" value="Headsuchestart">»</button>
</td>
</tr>
So, on submit he bring me to /Eventsuche/ but i would like to
go here: /Eventsuche/Value of Headsucheort
Thanks! :)
<button onclick="window.location.href='/Eventsuche/' + document.getElementById('Headsucheort').value">»</button>
Didn't test but
If you really must do it in PHP, add this to Eventsuch:
if ( isset($_POST['Headsucheort']) ) {
header('location:http://www.your-url.com/Eventsuche/'.$_POST['Headsucheort']);
exit;
}
I see two ways to the that.
first:
you can add your variable to the end of your action value such as: action="Eventsuche?var=somevalue"
and second one would be:
as a hidden input and even tho it is hidden, php will capture it on submit as in:
<input type="hidden" name="myvar_name" value="my_var_value" />
i think this should do it.