I've started learning PHP. Managed to setup things.
I'm using php version 5.3.13.
I'm trying to post some info to a html form and receive it in a php file.
For the purpose i'm using $_Post variable and the ouput at the php file is blank.
Below is the html code.
<body>
<form action="report.php" method="POST" >
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
</body>
And below is the report.php code
<html>
<head>
<title></title>
</head>
<body>
<?php
$name = $_POST['firstname'] ;
print($name);
?>
</body>
</html>
Can any one advise what i'm missing ?
Thanks
Here is a super simple example, I suggest you begin to look for example tutorials # your favorite search engine, or buy a book.
Edit: Do you even have PHP installed? you mention inetpub which is a IIS path.
<?php
error_reporting(E_ALL);
if($_SERVER['REQUEST_METHOD']=='POST' && !empty($_POST['firstname'])){
//Do something with posted data
$out = htmlentities($_POST['firstname']).' has been abducted!';
}else{
//Form has not been posted so show form
$out = <<<FORM
<form action="" method="POST" >
<label for="firstname">First name:</label>
<input type="text" id="firstname" name="firstname" /><br />
<input type="submit" value="Report Abduction" name="submit" />
</form>
FORM;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My first test Script</title>
</head>
<body>
<h1>My first test Script</h1>
<?php echo(isset($out))?$out:null; ?>
</body>
</html>
Related
I need the HTML File below to connect to different PHP Files as these connect to different tables in a database. I have used JAVA Script to submit an action when the button is pressed but no matter what, the file will only connect to the Prepared.php file and never connect to the Prepared2.php file. Ihave tried labeling differently and many other concepts but cannot seem to get the file to work.
Please find code below:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> BBC Database search </title>
</head>
<body>
<center>
<h1> BBC Database search </h1>
<script type="text/javascript">
function submitAction(act) {
document.sample.action = act;
document.sample.submit();
}
</script>
<form action="Prepared.php" method="post">
Search Brands: <input type="text" name="term"
onClick="submitAction('Prepared.php')"/><br />
<input type="submit" value="Submit" />
<form action="Prepared2.php" method="post">
Search Available Clips: <input type="text" name="clips"
onClick="submitAction('Prepared2.php')" /><br />
<input type="submit" value="Submit" />
</center>
</form>
The js code is totally unnecessary, and wrong, remove it and the onsubmit.
Then close the first <form> tag with a </form> Currently you have the second form within the first and thats not legal
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> BBC Database search </title>
</head>
<body>
<center>
<h1> BBC Database search </h1>
<form action="Prepared.php" method="post">
Search Brands: <input type="text" name="term" />
<br />
<input type="submit" value="Submit" />
</form>
<form action="Prepared2.php" method="post">
Search Available Clips: <input type="text" name="clips" />
<br />
<input type="submit" value="Submit" />
</form>
I am trying to pass the 'name' text field input to blank2.php. I can send the data across
but anything after I type the space bar all the other input after it is omitted. What am I missing?
blank.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>First Page</title>
</head>
<body>
<form action="http://www.example.com/blank2.php" method="post">
<label for="name"></label>
<input type="text" name="name" placeholder="Name" id="name">
<div>
<input type="submit" id="submit" name="submit" value="Send">
</div>
<div>
</form>
</body>
</html>
Here is the second page:
<?php
session_start();
$_SESSION['name'] = $_POST['name'];?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Second Page</title>
</head>
<body>
<form action = "http://example.com/blank3.php" method="post">
<label for="name"></label>
<input type="text" name="name" placeholder="Name" id="name" value=<?php echo $_POST['name'];?>>
<br>
<div>
<input type="button" id="submit" name="submit" value="Send Message">
</div>
</form>
</body>
</html>
I'd really appreciate if if anyone can assist me.
Put quotes around the value.
<input type="text" name="name" placeholder="Name" id="name" value="<?php echo $_POST['name'];?>">
I have a very simple HTML form that is supposed to send information to the file written in action attribute via GET but somehow it's transfering the information back to index.php:
index.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form acton="process_form.php" method="get">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="" />
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>
process_form.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>
The bizarre aspect is that when I submit the form, the URL shows that it is not even using process_form.php:
http://127.0.0.1/Learning/?username=test&email=x%40test.com&submit_btn=Submit
If I manually change the URL to include process_form.php it seems to be working fine and I get the results I am looking for:
http://127.0.0.1/Learning/process_form.php?username=test&email=x%40test.com&submit_btn=Submit
On my development computer, I'm running EasyPHP 14.1 local WAMP server and thought it might be the root of the problem so I uploaded the files to my website that is running newest PHP on Apache, but the problem still exists there.
What am I doing wrong?
you have a typo error in action; you have given acton. Should be like this:
<form action="process_form.php" method="get">
First thing - you have a typo:
<form action="process_form.php" method="get">
^
The second thing - in my opinion the best method of handling forms is using POST method, not GET, so I would change it to:
<form action="process_form.php" method="post">
and in process_form.php I would use $_POST instead of $_GET
After digging around your question,
Index.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form action="process_form.php" method="get">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="" />
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>
process_form.php
<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>
Note: If you will not specify form method, By default it will take GET method. So please make sure action should be perfect.
Above code just copy and paste, it should work perfect.
Ask me for further clarification.
Thanks,
Gauttam
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<form name="log" method="GET" action="login.php">
username <input type="text" name="usr" style="width: 242px"></input><br>
password <input type="password" name="psw" style="width: 242px"></input><br>
<input type="submit" style="width: 78px" value="تسجيل الدخول">
</form>
</body>
</html>
this is my simple php file
<?php
echo $_GET["usr"];
?>
when i pressed the submit I excepted it will print the username but it gave me this
please can someone tell me what is the problem, sorry for my bad English
You are not running the file on a php server... you are just reading the file in the browser, try loading the page from a URL like: http://localhost/mypage.php
Ok my first time asking question here. This as been very helpful in the past but now i'm lost.
I'm trying to understand how php work with the help of a book. So i did the exercise as it was shown in the book and the result if not what it should be.
Here's the code:
<div id="content">
<p>Here's a record of everything in the REQUEST array:</p>
<?php
foreach($_REQUEST as $value) {
echo "<p>" . $value . "</p>";
}
?>
</div>
<div id="footer"></div>
</body>
And here's the result:
Here's a record of everything in the REQUEST array:
" . $value . "
"; } ?>
Why is not showing the info it is suppose to? Thanks.
Ok here's all the code:
showRequestInfo.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html
> xmlns="http://www.w3.org/1999/xhtml"> <head> <meta
> http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link
> href="/wamp/www/livrephp/css/phpMM.css" type="text/css"
> rel="stylesheet" />
>
> <title>Untitled Document</title> </head>
>
> <body> <div id="header"><h1>PHP & MySQL: The Missing
> manual</h1></div>
> <div id="example">Example 3-2</div>
>
> <div id="content">
> <p>Here's a record of everything in the REQUEST array:</p>
> <?php foreach($_REQUEST as $value) { echo "<p>" . $value . "</p>"; } ?>
>
>
> </div>
> <div id="footer"></div> </body> </html>
And this goes with this file called "socialEntryForm.php"
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="/wamp/www/livrephp/css/phpMM.css" rel="stylesheet" type="text/css" />
<title>Untitled Document</title>
</head>
<body>
<div id="header"><h1>PHP & MySQL: The misiing manual</h1></div>
<div id="example">Example -1</div>
<div id="content">
<h1>Join the missing manual (Digital) Social Club</h1>
<p>Please enter your online connections below:</p>
<form action="../showRequestInfo.php" method="post">
<fieldset>
<label for="first_name">First Name:</label>
<input type="text" name="first_name" size="20" /><br />
<label for="last_name">Last Name:</label>
<input type="text" name="last_name" size="20" /><br />
<label for="email">Email Address:</label>
<input type="text" name="email" size="50" /><br />
<label for="facebook_url">Facebook URL:</label>
<input type="text" name="facebook_url" size="50" /><br />
<label for="twitter_handle">Twitter Handle:</label>
<input type="text" name="twitter_handle" size="50" /><br />
</fieldset>
<br />
<fieldset class="center">
<input type="submit" value="Join The Club" />
<input type="reset" value="Clear and Restart" />
</fieldset>
</form>
</div>
<div id="footer"></div>
</body>
</html>
Are you sure your file is a PHP file and it's being run on a PHP enabled server? The browser seems to be receiving the code unparsed, thinking that there's a tag starting at <?php and ending at the first <p> tag. If you look at the source, you'll probably see your PHP code, untouched by the server.
In other words: Your code is correct and the problem is your file type or server configuration. If you are indeed using a server on your machine, make sure you're running the file right, e.g. if it's in the root, open http://localhost/your_file.php, and not C:\xampp\htdocs\your_file.php.
EDIT: Just for the heck of it, I replicated your issue with a fiddle. I got the exact same output as you, meaning it's not getting parsed by the server. Who said JSFiddle was only good for JavaScript?
$_REQUEST Contains data which is gathered from cookies, $_POST and $_GET .. Are you sure that your data is properly assigned?
Take this example.
print_r($_REQUEST); just doing that without no <form method="get/post"> will produce a blank array, that might be why you are getting nothing
Your snippet is correct.. you are lacking a html form to go with that..
Example:
<form method="POST">
<input type="submit" name="test" value="ThisIsCorrect">
</form>
With your code you have shown your question.. your $_REQUEST array will return the value of the button. In this case "ThisIsCorrect"
Moral Of this?
Ensure that you are using using post/get/cookies before calling the $_REQUEST, and for future reference, just using $_POST & $_GET is cleaner to use.. But that is down to my personal preference.
How is the $_REQUEST Array constructed?
Consider this:
the array will contain the name as the array key and the value as the value..
So taking this into account:
<form method="POST">
<input type="text" name="username">
<input type="submit" name="test" value="ThisIsCorrect">
</form>
For your text box & Submit button the array will be:
array ("username" => "UserInputData",
"test" => "ThisIsCorrect");