Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
what I want to do is start a php session for the username, right after the form so it brings up the username once the user has pressed submit.
Here's the code for the form I have:
<form name="login" method="post">
<input type="text" name="username" placeholder="Username"/>
<input type="submit" name="login" value="Login" />
</form>
What do I do after that? Thanks.
Here is a simplified way; put this on top of the page (above) the html code:
if (isset($_POST['login']) {
session_start();
$_SESSION['name'] = $_POST['name'];
}
Now use that new Session variable where you need as the username. If you close your browser. It's no longer stored. (Unless you set a cookie.)
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
<form name="form11" method="post" action="hpdata.php" enc type="multipart/form-data">
<input name="pro" id="pro" type="hidden" value= "CMS" />
<input name="piror" id="piror" type="hidden" value= "P1" />
<input name="stat" id="stat" type="hidden" value= "In Progress" />
<input type="submit" name="submit" id="submit" class="groovy button" value="...">
</form>
in this code I can't see the data
hidden attribute just use for hide item from the UI. but still you can acsess them after form is submitted using $_POST['id here'] (if form method is get you should get it through $_GET[])
the code you provided has nothing to do with mysql.
It is a html fragment. It contains hidden inputs. If you want to make them visible remove type="hidden".
But most likely there is a purpose why they are hidden. Often this is done to keep values for different form pages or to present the user with pretty values, but send easier to handle versions to the server. (e.g. dates can have different formats in different countrys, but its easier to just send them in a standardized form --> this one would be in a hidden input.)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i'm a PHP begginer. I'm actually trying to make a simple login system. I did it, but only for one page... Like you login then you go to index, it works... If i want to go to another page it requires me again to login. I've tried to make the form like this:
<form action="index.php" action="stats.php" method="post">
The both classes have the method POST. I've tried to double the form too like:
<form action="index.php" method="post">
<form action="stats.php" method="post">
It still doesn't work.
First of all you need to have
session_start();
on every page you need to check if the user is logged in
Then at the page that you decide if the credentials are correct you need to set a session variable eg.
$_SESSION['UserIsLoggedIn'] = true;
$_SESSION['UserId'] = $userid;
It is good to create a function that will tell you if the user is logged in
function UserIsLoggedIn(){
if (isset($_SESSION['UserIsLoggedIn']) && $_SESSION['UserIsLoggedIn'])
return true;
else
return false;
}
So every time you need to check if the user is logged in you should check the following
if (UserIsLoggedIn()) { ... }
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
When pressing send on my contact page (www.mainmanfilms.com/contact.html) I am sent to my contact-form-handler.php page that requires the visitor to re-type their information. Is there a way to may it one-fluid step? Ideally, they press send and receive my thank-you message. Anything you can offer is appreciated.
Yes. You can leave the action attribute empty and configure the form to POST to itself.
Normally, you'd do something like this:
<form action="contact-form-handler.php" method="post">
If you want to process the form and display the output in the same page, you need to make the following change (note the action attribute being empty:
<form action="" method="post">
An example:
<?php
if (isset($_POST['formsubmit'])) {
//form was submitted, do other stuff
echo $_POST['username']; //example
}
?>
<form action="" method="post">
<input type="text" name="username" />
<input type="submit" name="formsubmit" />
</form>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a php form with dynamic checkboxes. It must connect to sql server and get their count and names. At the end I want submit the checked boxes.
example
I get from db some vegetables, for a receipt, and add checkboxes in my form. The user will check some of the and submit it.
I can't make <input type=checkbox id=...> because when post it i will not know the names of them. For that reason, i made a js function and when a checkbox checked, i add it to a array.
Now i want ask you, how i can submit this array and after that get the values at post.php file?
Create your checkboxes like:
<input type="checkbox" name="veg[]" value="tomato">
<input type="checkbox" name="veg[]" value="lettuce">
<input type="checkbox" name="veg[]" value="carrot">
<input type="checkbox" name="veg[]" value="celery">
Even if you don't know the names, you can iterate through the checkbox using:
<?PHP
foreach($_POST["veg"] as $veg){
echo $veg;
}
?>
Have you added name attributes to your checkboxes? Like so:
<input type="checkbox" name="potatoes" />
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I need to make a custom code which will help me to find location of a particular IP entered through a text box.
When I searched the internet what I found is only providing automatic detection of IP and it's location. Please help me.
I am using this code in my website
Please try it yourself -
<?php
function countryCityFromIP($ipAddr)
{
$url = "http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json";
$d = file_get_contents($url);
return json_decode($d , true);
}
if(isset($_REQUEST['submit'])){
$ip=countryCityFromIP($_REQUEST['ip']);
//print_r($ip);
echo $ip['cityName'];
}
?>
<form method="post">
<input type="text" name="ip" />
<input type="submit" name="submit" value="Find" />
</form>
please use print_r($ip); to get the details which parameter will get from the url.
Take a look at the MaxMind GeoIP database. A tutorial for that one can be found at http://www.phpandstuff.com/articles/geoip-country-lookup-with-php. There are various other databases available as well. For that take a look at https://stackoverflow.com/search?q=geolocation+%5Bphp%5D