I get the following 404 error when trying to access a PHP file on MAMP
"The requested URL /‘welcome.php’ was not found on this server."
Both the html file and the php file run fine via localhost just not from the file action.
They are in the same location and the action looks like action='welcome.php'
<html><head charset=“utf-8”>></head><form action=‘welcome.php’ enctype="text/plain" method=“post”>
First name: <input type="text" name="firstname"><br> Last name: <input type="text"
name="lastname"> <button action=“submit”>Submit </button> </form> </html>
welcome.php looks like this
<html> <body> Welcome <?php echo $_POST["name"]; ?><br> Your email address is: <?php echo
$_POST["email"]; ?> </body> </html>
You have a few curly quotes in your code “ ” and ‘ ’ which will explain the "file not found" error for your form's action action=‘welcome.php’. You should also remove enctype="text/plain" - consult this answer on Stack for more information about it.
You are also using the wrong names name="firstname" and $_POST["name"].
Also name="lastname" and $_POST["email"], those must match.
Your Html file should now read as:
<html>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
and welcome.php file:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
The requested URL /‘welcome.php’ was not found on this server.
This is because you use wrong quotes (quotation marks) in your HTML. In markup you should use nothing else then " or '.
So your code should looks like:
<html>
<head charset="utf-8"></head>
<body>
<form action="welcome.php" enctype="text/plain" method="post">
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
<button action="submit">Submit</button>
</form>
</body>
</html>
Related
I have 2 files, index.html, and welcome.php.
index.html:
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
And here is the PHP:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
Echo seems to work whenever i'm not using $_POST, with just regular text or variables. Is there something I'm doing wrong? I am also writing this code on repl.it, could that have something to do with it? Major newbie here.
I need help with some coding.
I watched some tutorials from W3Schools and youtube, but I just don't get it.
<!DOCTYPE html>
<?php
if (isset($_POST["Push me"]))
echo $_POST['name']
?>
<html>
<body>
Registration
<form action="/action_page.php" method="get" target="_blank">
Insert name <input type="text" name="fname"><br>
<input type="submit" value="Push me">
</form>
</body>
</html>
When you push the button there should be a name that was typed into the field.
Example:
If you enter the name Simon after pushing the button it should write Hello Simon under the button
if (isset($_POST["fname"]))
// ^^^^^
echo $_POST['fname'];
// ^^^^^ ^
<form action="/action_page.php" method="post" target="_blank">
// ^^^^
Your PHP code is out of the HTML tag, I have place the php code in the DIV under the button, i.e. to display "Hello xxxTheNameYouEnterInTheInputxxx"
The if condition in your PHP code should be like if(isset($_POST["fname"])) instead of if(isset($_POST["Push me"]))
i.e. $_POST["NameOfTheInputElementInTheForm"]
<form action="/action_page.php" method="get" target="_blank"> should be like <form action="/test.php" method="POST"> i.e. Method is POST and action should be the name of the file, remove target="_blank"
Here is the full code, save it as test.php
<!DOCTYPE html>
<html>
<body>
Registration
<form action="/test.php" method="POST">
Insert Name: <input type="text" name="fname"><br>
<input type="submit" value="Push me">
</form>
<hr>
<div>
<?php
if (isset($_POST["fname"])){
echo "Hello " . $_POST['fname'];
}
?>
</div>
</body>
</html>
I have a PHP file that parses a JSON list and feeds it to a combobox:
<?php
$jsonData = '{"marco":"marco#test.it", "giovanni":"giovanni#mail.it"}';
$json = json_decode($jsonData, true);
$opts = '';
foreach($json as $name => $email)
{
$opts .= '<option value="'.$email.'">'.$name.'</option>';
}
echo ' <select name="Team1">'.$opts.'</select> <br> ';
echo ' <select name="Team2">'.$opts.'</select> <br>';
?>
I'm trying to include it in an HTML page, so that when it loads it will show the combobox:
<html>
<head>
<title> Invio Mail </title>
</head>
<body>
<form name="mail" action="mailer.php" method="post">
<p>
<center><b> Invio mail </b>
<br>
<br>
<? include("combobox.php") ?><br>
Messaggio: <input type="text" name="name" rows="5" required><br>
<br>
<center><input type="submit" value=" Invia "></center><br>
</form>
</body>
</html>
But I can't manage to make them appear!
I don't need a real time update, it's enough that the list is updated when the page is created.
Also, I can't manage to read the associated value from the combobox.
Make sure that the HTML page has the .php extension instead of .html and check if your webserver supports short open tag for php.
Edit:
You can check the phpinfo() if short_open_tag has the value on.
Edit 2:
You can access the selected value in your mailer.php with $_POST['Team1'] and $_POST['Team2']
Edit:
<? include("combobox.php") ?>
to
<?php include("combobox.php") ?>
So, html code will be:
<html>
<head>
<title> Invio Mail </title>
</head>
<body>
<form name="mail" action="mailer.php" method="post">
<p>
<center><b> Invio mail </b>
<br>
<br>
<?php include("combobox.php") ?><br>
Messaggio: <input type="text" name="name" rows="5" required><br>
<br>
<center><input type="submit" value=" Invia "></center><br>
</form>
</body>
</html>
I am trying to see inputed texting using HTML and PHP.
From what I have written so far, I am trying to display a name and email after running through PHP, but the only thing shown is:
Welcome
Your email address is:
HTML:
<form action="index.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
</body>
</html>
PHP:
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is:
<?php echo $_POST["email"]; ?>
</body>
</html>
How can I make it so I see the input submitted?
I have written a code to get First name,last name and NIC no. If First name is missing I will show a error call "missing" infront of the textbox. All this thing is working and it will send the information in to the same page.
If first name is missing show the error in the same form which will allow user to refill it. If the user entered information correctly, I need to redirect user to another form. How can I do it?
<?php
$fnameerr="";
$name="";
if($_SERVER['REQUEST_METHOD']=="POST")
{
if(empty($_POST["fname"]))
{
$fnameerr="Missing";
}
}
?>
<head>
<title>Untitled Document</title>
</head>
<body>
<form name="form1" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
First Name:<input type="text" name="fname" value="<?php echo htmlspecialchars($name);?>">
<span class="error" style="color:#FF0000">*<?php echo $fnameerr;?></span>
<br/><br/>
Last Name:<input type="text" name="lname" /><br/><br/>
NIC:<input type="text" name="nic" /><br/><br/>
<input type="submit" name="sub" value="Register"/>
<input type="reset" name="re" value="Reset"/>
</form>
</body>
</html>
Use header() to redirect
if(empty($_POST["fname"])) {
$fnameerr="Missing";
}
else {
header("Location: anotherForm.php");
}