Does anyone know how to change PHP Variable values by HTML Form ? I am using php script to display the values on HTML Pages
but i want to change the values by form not by editing php files but i don't know how to do it
here is my php script [data.php]
<?php
$web_title_en = "JDST BLOG"; // Website Title
$web_subtitle_en = "blah blah blah"; // Website Subtitle
?>
and html (for display the values) [index.html]
<html>
<head>
<?php include 'data.php';?>
</head>
<body>
<h1><?php echo $web_title_en; ?></h1>
<h4><?php echo $web_subtitle_en; ?></h4>
</body>
</html>
If you want to process html forms with php you should read this w3c tutorial. Your form would be something like this:
<html>
<body>
<form action="data.php" method="post">
Title: <input type="text" name="title"><br>
Subtitle: <input type="text" name="subtitle"><br>
<input type="submit">
</form>
</body>
</html>
And this would be data.php (a merged version with your index.html)
<?php
$web_title_en = $_POST['title']; // Website Title
$web_subtitle_en = $_POST['subtitle']; // Website Subtitle
?>
<html>
<body>
<h1><?php echo $web_title_en; ?></h1>
<h4><?php echo $web_subtitle_en; ?></h4>
</body>
</html>
I'm not sure about your exact situation (perhaps the question could be reworded?), but this might be a useful document on how to handle form data:
http://www.w3schools.com/php/php_forms.asp
Related
I have tried of few things, but this is just on the edge of what I understand, so I am grasping at straws of the advice I find online. I feel like I am missing some vital step or something, but I just don't know what it is. Here is my code:
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<?php
if($_POST['formSubmit'] == "Submit")
{
$varImage = $_POST['formStuff'];
}
?>
<form action="welcome.php" method="get">
Image URL: <input type="text" name="stuff"><br>
<input type="submit">
</form>
Image Shown:<br><br> <?php echo $_GET["stuff"]; ?>
</body>
</html>
And here is welcome.php:
<html>
<body>
Image Shown: <br><br><?php echo $_GET["stuff"]; ?>
</body>
</html>
Once this is figured out, I plan on figuring out how to make the image the background instead of just an image. Shrug.
try this in welcome.php
<html>
<body>
<?php if(isset($_GET['stuff'])) { ?>
Image Shown: <br><br><img src="<?php echo $_GET['stuff']; ?>"/>
<?php } ?>
</body>
</html>
You need to use your url in tag :
Like that way :
<img src="<?php echo $_GET['stuff']; ?>"/>
Here is my Code :
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" action="../../../wamp/www/abc.php" method="get">
<input type="text" name="text1" id="username" />
<input type="submit" />
</form>
</body>
</html>
The abc.php file is located in C:/wamp/www/abc.php
<html>
<body>
Hello World
<?php
echo "Hello";
echo $_GET["username"];
?>
</body>
</html>
In the form, when I press the Submit button, only "Hello World" is displayed.
The value entered in the textbox is not displayed at all. Even the "Hello" message printed inside the php code is not displayed.
How can i display the Value ?
text1 is the name of your input, so the correct PHP code would be.
<?php
echo "Hello ";
echo $_GET['text1'];
?>
Try the below, get array is created using name attr not id one.
echo $_GET["text1"];
There is two solution for you should use :
First Way :Change your php code:
<?php
echo "hello";
echo $_GET["text1"];
?>
Second Way: Chnage your HTML
<input type="text" name="username" id="username"/>
If second "Hello" from echo is not displayed, there is a problem with your PHP installation.
I have used a form to send two variables from one page to another. Then I wanted the user to be able to click on a link (staying on the website) then once on the third page the variables to still be able to be used.
First page (which works fine):
<html>
<head>
<title> Form </title>
</head>
<body>
<form action="result.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>
<br />
</body>
</html>
Then the second page (which displays the variables correctly):
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your email address is: <?php echo $_POST['email']; ?>
link
</body>
</html>
Then when you click on the link from the second to the third (below) it doesn't work:
<html>
<head>
<title> Form </title>
</head>
<body>
<?php echo $_POST['name']; ?>
</body>
</html>
Thanks in advance for any help!
You have to put $_POST['name'] and $_POST['email'] in session variables.
One way to do that is:
link
On name.php you will have them as $_GET variables
if you just want to use these values on 3rd page only then better to use the above GET method. Otherwise you can put these values in session
Your second (result.php) page should look like this:
<?php
$_SESSION['name']= $_POST['name'];
$_SESSION['email']= $_POST['email'];
?>
<html>
<body>
Welcome <?php echo $_POST['name']; ?><br>
Your email address is: <?php echo $_POST['email']; ?>
link
</body>
</html>
And you third page (name.php) will work when you put it like this:
<html>
<head>
<title> Form </title>
</head>
<body>
<?php echo $_SESSION['name']; ?>
</body>
</html>
A php 'if statement' example from a tutorial by Kevin Yank doesn't seem to work. Specifically, both branches of the conditional appear when the page loads.
I have also tried changing to the non-shorthand 'if' syntax, to no avail.
Is the problem something other than syntax?
The code is as follows:
<!DOCTYPE html>
<html>
<head>
<title> Sample Page </title>
</head>
<body>
<?php if(isset($name)) : ?>
<p> Your name: <?php echo ($name); ?> </p>
<p> This paragraph contains a link that passes the name variable on to the next document. </p>
<?php else : ?>
<!-- No name has been provided, so prompt the user for one -->
<form action="<php echo($PHP_SELF); ?>" method="get">
Please enter your user name:
<input type="text" name="name">
<input type="submit" value="ok">
</form>
<?php endif; ?>
</body>
</html>
This script left out a very important element >>> $name=$_GET['name']; <<<
The name must first be declared as a variable.
It has been added inside this line: <?php if(isset($name)) : ?>
See my code below: (tested and working)
<HTML>
<HEAD>
<TITLE> Sample Page </TITLE>
</HEAD>
<BODY>
<?php $name=$_GET['name']; if (isset($name)): ?>
<P>Your name: <?php echo($name); ?></P>
<P>This paragraph contains a
<A HREF="newpage.php?name=<?php echo(urlencode
($name)); ?>">link</A> that passes the
name variable on to the next document.</P>
<?php else: ?>
<!-- No name has been provided, so we
prompt the user for one. -->
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD="GET">
Please enter your name: <INPUT TYPE="TEXT" NAME="name">
<INPUT TYPE="SUBMIT" VALUE="GO">
</FORM>
<?php endif; ?>
</BODY>
</HTML>
Plus as an added bonus (tested and working), you can use the PHP code below, inside your goodone.php file to echo the name after you clicked on the link after you submitted the form. You can do whatever you wish from hereonin, for database use, etc.
<?php
echo($_GET['name']);
// do something else
?>
I have a file test.php with the following code:
<html>
<head>
<title>Listing 10.2 </title>
</head>
<body>
<div>
<form method="post" action="test.php" >
<p> <input type="text" name="guess"/> </p>
</form>
<?php
if(!empty($_POST['guess'] )) {
print "Last guess $_POST['guess']";
}
?>
</div>
</body>
</html>
I have a problem with the form not showing up. However, if I remove the PHP portion of the code, it is visible. What is my problem?
You can't embed the $_POST variable into the string like that, trying changing the php section to:
<?php
if(!empty($_POST['guess'] )) {
print "Last guess {$_POST['guess']}";
}
?>
Use . for combine values and strings
if(!empty($_POST['guess'] ))
{
echo "Last guess".$_POST['guess'];
}