Dynamic php submit [closed] - php

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" />

Related

Starting a PHP Session from HTML log in form [closed]

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.)

how to show the hidden data from mysql database [closed]

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.)

Any Site That Displays The Received Text? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
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
So pretty much what I am looking for is a site that simply accepts POST requests, and the site then just displays the text received from the POST request.
For example, lets say that I POSTed "Hello, world!" to the site, if I looked at the contents of the page, it just said "Hello, world!". I need this for testing/developing purposes.
If not, could somebody possibly create a PHP script for this? I don't know PHP, otherwise I would do it myself :)
Thanks
EDIT: Sorry for the extremely easy question, I didn't realise it was this easy. Thanks for the answers :)
<?php
header("Content-Type: text/plain");
print_r($_POST);
This uses print_r to dump the content of the $_POST array. The page content type of text/plain is needed to prevent creating an XSS vulnerability.
Try this
First create a file names mypage.php then save this code.
<?php
if(isset($_POST['myText']))
{
echo $_POST['myText']
}
<form action='mypage.php'>
<input type='text' name='myText'>
<input type='submit'>
</form>
?>
Assume your form looks like this
<form method="POST">
<input type='text' name='field'>
<input type='submit' value='Submit'>
</form>
The simplest way is write this code below it
<?php var_export($_POST); ?>
Write your own! Do this on any website you have
Simply print_r($_POST); should suffice on a blank page

How to Make Checkboxes Into Array In Dreamweaver [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
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
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.
Improve this question
I am designing a seat reservation system. I want the check boxes to represent the seats.
I want to know how to make each check boxes into array and how to group all the check boxes in a single canvas so that it will store multiple values in one single variable in the database column.
I am using Dreamweaver and PHP.
You should do some like below:
<input type="checkbok" value="1" name="seat[]" />
<input type="checkbok" value="2" name="seat[]" />
<input type="checkbok" value="3" name="seat[]" />
<input type="checkbok" value="4" name="seat[]" />
....

PHP code to find an IP location from the IP entered through a input box [closed]

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

Categories