This question already has answers here:
PHP not rendering in HTML
(1 answer)
PHP script not working in HTML file
(6 answers)
PHP inside HTML doesn't work
(5 answers)
Closed 1 year ago.
My code is
<form action = "insert.php" method = "POST">
<div class="title-block">
<input type="text" name="rater_full_name" />
</div>
<div class="title-block">
<input type="text" name="rater_company_name" required />
</div>
<div class="title-block">
<input type="text" name="rater_ref" />
</div>
<div class="title-para">
<textarea rows="5" name="rater_suggestion"></textarea>
</div <div align="left"><div class="btn-block">
<input type="hidden" name="PID" value="<?php echo $PID; ?>"> <button type="submit" name="submit" value="submit">Submit Feedback</button>
</div>
</form>
It's not storing the variable $PID value, it is storing complete code inside quotations("") Please suggest best way to do so..
Thanks in advance.
Save the file as .php rather than .html
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
first file is index.php
<?php include('loginform.php');?>
second file is loginform.php
<?php
<html>
<body>
<form action="" method="post">
<label>Username</label>
<input type="text" name="username"><br>
<label>Password></label>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="login">
</form>
Register here
</body>
</html>
?>
third file is register.php
<html>
<body>
<form action="" method="post">
<label>FirstName</label>
<input type="text" name="firstname"><br>
<label>LastName</label>
<input type="text" name="lastname"><br>
<label>Email</label>
<input type="email" name="email"><br>
<label>UserName</label>
<input type="text" name="username"><br>
<label>Password</label>
<input type="password" name="password"><br>
<input type="submit" name="submit" value="Register">
</form>
</body>
</html>
I have three files in the project first file is the index file which is shown whenever the user opens the website It contains two things login form and a link
ie register here.So i have wrapped all this in one single php file loginform.php
and included it in my index.php file so when I execute this in my localhost web server it shows a error like this
Parse error: syntax error, unexpected '<' in C:\xampp\htdocs\cms\loginform.php on line 2
How can I tackle this problem please tell me?
The loginform.php file isn't a PHP source file, it's just an HTML file. Remove the enclosing <?php and ?> from it and you should be OK.
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 6 years ago.
I am trying to conditionally create a fieldset in the top right of my website that will either prompt the user to login, or show their username and give them the option to logout.
I am using embedded php within my html document in order to achieve this. Unfortunately, both fieldsets are being displayed on my webpage. Can someone please explain to me what I am doing wrong? Thank you!
<div id="loginForm">
<?php
session_start();
if(isset($_SESSION['username'])){ ?>
<form action="endsession.php" method="post">
<fieldset width="100">
<legend>Welcome</legend>
<h3></h3>
<input type="submit" value="Logout"></input>
</fieldset>
</form>
<?php } else{ ?>
<form action="connection.php" method="post">
<fieldset width="100">
<legend>Login</legend>
<input type="hidden" name="submitted" id="submitted" value="1"/>
<label for="username">Username:</label>
<input id="username" name="username" type="text" ><br><br>
<label for="password">Password:</label>
<input id="password" name="password" type="password"/><br><br>
<input type="submit" value="Sign in"></input>
</fieldset>
</form>
<?php } ?>
</div>
Put session_start(); at the top of your page before any other code; just after PHP start tag
<?php
session_start();
<div id="loginForm">
....
and so on...
Hope it fixes the problem.
This question already has answers here:
Make a link use POST instead of GET
(11 answers)
Closed 7 years ago.
Is there a way to replicate this in <a href="blah.php">?
<form action="http://localhost/php/suburb_added.php" method="post">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
in suburb_added.php... i have this to capture
if (!empty($_POST['suburb']))
To a table form....
<td align="left"><a href="suburb_added.php"><?php echo $row['id'];?></td>
how to create the items below from a table? The goal is when I click the result from <?php echo $row['id'];?>, I should be able to get the value of "id" and process it in suburb_added.php using similar to if (!empty($_POST['suburb']))
<form action="http://localhost/php/suburb_added.php" method="post">
<input type="text" name="suburb" size="30" value="" />
what do you whant i don't understand?? I can help you
<?php
if(!isset($_POST['submit'])){
?>
<form action="" method="post" name="submit">
<b>Add a New Suburb</b>
<p>Name:
<input type="text" name="suburb" size="30" value="" />
<input type="submit" id="submit" value="Submit" name="submit" />
</p>
</form>
<?php
} else {
//paste here your code from http://localhost/php/suburb_added.php
echo "you doing post in this page.";
}
?>
<!--Try using header
like this:-->
if($_POST)
{
header('location:login-form.php');
}
else
{
echo "";
}
Change the PHP script so it uses $_REQUEST instead of $_POST. This variable combines the contents of $_POST and $_GET. Then you can have a link like
<?php echo $row['id'] ?>
This question already has an answer here:
PHP Using File_get_Contents() to pre populate a form [closed]
(1 answer)
Closed 7 years ago.
I am making a site that uses the file_get_contents to display a form. The form contains three fields and is as below. What I am trying to do is insert three values that I have generated from sql queries into this form.
Is there a way that I can send the values I have generated into the correct fields of the form?
Would I have to add some php to the top of the form that will allow it receive the values being passed from the file_get_contents function?
Calling the functions and form
//sql functions return values based on rowID
$updateTilte = $this->model->updateTitle();
$updatePrice = $this->model->updatePrice();
$updateDescription = $this->model->updateDescription();
$rightBox = file_get_contents( "templates/update_item_form.php" );
Update_item_form
<h2>Update Item!</h2>
<h4>Fill in the form to update an entry.</h4>
<form action="index.php" method="post">
<fieldset>
<input id='action' type='hidden' name='action' value='updateItem' />
<p>
<label for="fTitle">Title</label> <input type="text"
id="fTitle" name="fTitle" placeholder="title"
maxlength="25" required />
</p>
<p>
<label for="fPrice">Price</label> <input type="text"
id="fPrice" name="fPrice" placeholder="price"
maxlength="25" required />
</p>
<p>
<label for="fDescription">Description</label> <input type="text"
id="fDescription" name="fDescription" placeholder="description"
maxlength="500" required />
</p>
<p>
<div class="form-group">
<div class="controls">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</p>
</fieldset>
</form>
No. That's not what file_get_contents does, and it's not what it's for either. What you are looking for is include
It opens the file in PHP mode, executing whatever code it finds. That means you can use the variables you declared above inside the file, and PHP will replace them with their value.
Snippets:
$updateTilte = $this->model->updateTitle();
include "templates/update_item_form.php";
Form:
<label for="fTitle">Title</label> <input type="text"
id="fTitle" name="fTitle" placeholder="title"
maxlength="25" required value="<?php echo $updateTilte; ?> />
Note: include will immediately output the html in the file. Only include the file when you're ready to output everything.
This question already has answers here:
Html form posting, no data passed on [duplicate]
(2 answers)
Closed 8 years ago.
Edit: Yes, this is a duplicate, and the same answer is applicable. I didn't find the linked original when I searched on 3 sets of terms. Sorry!
Edit 2: yeah, name="something". I feel like such an idiot.
Edit 3: Well, no. The name attribute fixed my text fields, but not my checkboxes! My checkboxes now read like this:
<input type="checkbox" class="dot" id="stren1" name="stren1" checked="true" disabled>
but still don't show up in my var_dump!
Original Question:
I've been trying to save form data to a variable, and having no luck. Digging in to it, I discovered that my form data was not passing at all to my PHP! Below is a snippet from this gist (https://gist.github.com/farfromunique/35a5d6006e8d5690ca4d) :
<form action="store.php" method="post">
<input name="test" value="Test" type="hidden">
<div id="charSheet">
<div id="clanName">
<H1>Vampire: the Masquerade</H1>
</div>
<div id="plainText" class="section">
<div id="text1" class="lefty">
<label>Character's Name
<input type="text" id="characterName">
</label>
<br />
<label>Player
<input type="text" id="player">
</label>
<br />
<label>Chronicle
<input type="text" id="chronicle">
</label>
<br />
</div>
</div>
</div>
<!-- Snip! /-->
<input type="Submit" value="Save">
</form>
Currently, store.php has only this in it:
var_dump($_REQUEST);
Submitting the form results in this:
array (size=1)
'test' => string 'Test' (length=4)
Why is only my top-level, added-for-debugging input passing data? What am I doing wrong?
You need to use the name="" attribute, not id="".
use the 'name' attribute. simple HTML