I really don't know what is wrong with this script.. I really thought everything was right, but somehow my strpos syntaxs doesn't work properly or something. The $_POST['category'] is a select list with multiple selections permitted. So that's why I put it in an array, but maybe it is incorrect?
$cat_array = $_POST['category'];
foreach($cat_array as $key => $value )
{
if(strpos($value, 'n_') !== false)
{
// Do something about the new categories.
} else {
// work with existing categories
}
}
the html - I also have a jquery that handles the add category fields. The n_(number)-(value) is created by jquery.
<div>
<label for="category">Category</label>
<select name="category" size="10" multiple="MULTIPLE">
<option class="cat_1" value="1">Cars</option>
<option class="cat_2" value="2">Lego</option>
<option class="cat_3" value="3">Country</option>
<option class="cat_4" value="4">School</option>
<option class="cat_5" value="5">Cooking</option>
<option class="cat_6" value="n_6-test">test</option>
<option class="cat_7" value="n_7-Buuh">Buuh</option>
</select> <br>
<input type="text" name="new_cat" value="" size="40" maxlength="120" placeholder="Category Name"><input class="plus" name="" type="button" value="Add Category">
<p class="plus_comment"></p>
</div>
Your $_POST['category'] is not an array. After seeing your var_dump result, it must be a string only. If it as an array, the var_dump should display like this,
array (size=1)
1 => string '5' (length=1)
So, check your HTML code whether it passes an array.
EDIT: Change the category to category[]
try to your select list name
category[]
To make your category actually an array you have to append brackets to the category like this: category[]
So your HTML woul look like this
<div>
<label for="category">Category</label>
<select name="category[]" size="10" multiple="MULTIPLE">
<option class="cat_1" value="1">Cars</option>
<option class="cat_2" value="2">Lego</option>
<option class="cat_3" value="3">Country</option>
<option class="cat_4" value="4">School</option>
<option class="cat_5" value="5">Cooking</option>
<option class="cat_6" value="n_6-test">test</option>
<option class="cat_7" value="n_7-Buuh">Buuh</option>
</select> <br>
<input type="text" name="new_cat" value="" size="40" maxlength="120" placeholder="Category Name">
<input class="plus" name="" type="button" value="Add Category">
<p class="plus_comment"></p>
</div>
Related
I have this code here, within a form:
<form method="post" action="">
<div id="icon-themes" class="icon32"><br></div>
<h2 class="nav-tab-wrapper"><a class='nav-tab' href='?page=symbiostock-ecommerce-manager&tab=homepage'>Home Settings</a><a class='nav-tab nav-tab-active' href='?page=symbiostock-ecommerce-manager&tab=invoices'>Invoices</a><a class='nav-tab' href='?page=symbiostock-ecommerce-manager&tab=VAT'>VAT Settings</a><a class='nav-tab' href='?page=symbiostock-ecommerce-manager&tab=feed'>Google Product Feed</a></h2>
<br />
<label for="ssem_year_num">Year
<input name="ssem_year_num" value="2014" type="text" />
</label>
<label for="ssem_month_num">
Month
<select name="ssem_month_num">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option selected value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
</label>
<p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes" /></p>
</form>
Despite changing the values in the text and select area, they do not seem to change upon form submission, as the var_dump($_POST) result shows this:
array (size=3)
'ssem_year_num' => string '2014' (length=4)
'ssem_month_num' => string '8' (length=1)
'submit' => string 'Save Changes' (length=12)
Having run my HTML through the w3 validator, it appears the HTML is not broken, so I'm left wondering - why aren't the values reflecting user input upon submission?
for the input text try this:
<label for="ssem_year_num">Year
<input type="text" placeholder="2014" name="ssem_year_num" />
</label>
and in the select remove the 'selected' property:
....
<option value="8">August</option>
....
and see what happens.
i think your problem is this: php is a preprocessed language.
If you are grabbing var_dump($_POST) at the same page, nothing should be in $_POST since when you load the php, you have not posted your form yet. therefore it will be empty.
put your php into seperate file and call it via action="submit.php", then use var_dump($_POST) and see it works!
Try to rename:
<input type="submit" name="submit" id="submit">
To
<input type="submit" name="s1" id="s1">
And see if that resolves the issue.
I am assuming there is javascript on the page listening for a form.submit event.
This is my html form and php file i have to insert my budget dropdown values by select into database
i have to select values from budget and selected value can insert in database
and my data is inserting in my database when i click twice on submit button
<form action="insert.php" method="post" id="register-form" onsubmit=" return add();">
<div class="label"> Name</div><input type="text" id="name" name="name" /><br />
<div class="label">Email</div><input type="text" id="email" name="email" /><br />
<div class="label">Phone Number</div><input type="text" id="phone" name="phone" /><br />
<div class="label">budget</div>
<select id="budget" name="budget">
<option value="">select</option>
<option value="1">0-100</option> <!-- first option contains value="" -->
<option value="2">100-200</option>
<option value="3">200-300</option>
</select>
<br /><br />
<input type="submit" onclick="add()" name="submit" />
<div id="message"></div>
</form>
insert.php
<?php
include("config.php");
if(isset($_POST['submit'])){
$name=$_POST["name"];
$email=$_POST["email"];
$phone=$_POST["phone"];
$budget=$_POST["budget"];
$insert_query="insert into form(name,email,phone,budget) values ('$name','$email','$phone','$budget')";
$con=mysql_query($insert_query);
}
?>
Do the following:
<select id="budget" name="budget">
<option value="">select</option>
<option value="0-100">0-100</option> <!-- first option contains value="" -->
<option value="100-200">100-200</option>
<option value="200-300">200-300</option>
</select>
Ensure that your field in the database is string/varchar
Re-visit the add() as well. That might be the cause for inserting successfully after the second click.
dropdown pass option value in variable so change the option value which you want to insert in database
<select id="budget" name="budget">
<option value="">select</option>
<option value="0-100">0-100</option> <!-- first option contains value="" -->
<option value="100-200">100-200</option>
<option value="200-300">200-300</option>
</select>
<select id="budget" name="budget">
<option value="">select</option>
<option value="0-100">0-100</option> <!-- first option contains value="" -->
<option value="100-200">100-200</option>
<option value="200-300">200-300</option>
</select>
if u want to select multiple option u use
<select id="budget" name="budget" multiple="multiple">
The $_POST["budget"]; is taking the value that is in the option, in this case the value for "0-100" is 1. If you want the value to be stored in the database use "0-100" as the value.
As far as the insert problem goes, try using this syntax:
$budget=$_POST['budget'];
$query = "INSERT INTO users ( database_budget )
VALUES ('$budget');";
the top value being the value in the database and the bottom value being the post value.
This is assuming that you're connecting to the database correctly. Also use single quotes for post values not double quotes.
I tried searching this and it is probably a really simple solution but I can't figure out how to combine an option field with a text field in html/php/js. Basically I just need the user to be able to select whether it is http or https and then type in the domain. It should then be submitted through _GET as a single variable.
<select>
<option value="http://">http://</option>
<option value="https://">https://</option>
</select>
<input class="span4" id="domain" name="domain" type="text">
<button class="btn btn-success" type="submit">Submit</button></form>
Any input would be appreciated.
I would combine them AFTER the submit...
HTML Page (You need to name your SELECT):
<select name="type">
<option value="http://">http://</option>
<option value="https://">https://</option>
</select>
<input class="span4" id="domain" name="domain" type="text">
<button class="btn btn-success" type="submit">Submit</button></form>
PHP Page:
$type = $_GET['type'];
$name = $_GET['domain'];
$combined = $type . $name;
Assuming you really "meant"
submitted through _GET as a single variable
You would end up with ie. https:// as $type and www.example.com as $name ... then the variable $combined should have a value of https://www.example.com
Select needs a name.
<form>
<select name="protocol">
<option value="http://">http://</option>
<option value="https://">https://</option>
</select>
<input class="span4" id="domain" name="domain" type="text">
<button class="btn btn-success" type="submit">Submit</button>
</form>
I'm trying to pass two variables (a search query (String) and a column name (also a String)) via a HTML form. The first string is entered into a text box and the second is selected from a drop-down menu.
Obviously this method doesn't work:
<h3>Search for a Customer</h3>
<form action="search.php" method="get">
<input type="text" id="sString">
<select name="sField">
<option value="Name">Name</option>
<option value="HostID">Host ID</option>
<option value="OrderNumber">Order Number</option>
<option value="Theme">Theme</option>
</select>
<input type="submit" value="submit"/>
</form>
You need to give your <input> field a name in order for this to work. Unnamed inputs won't get passed through the form post.
You don't have a 'name' parameter on your sString input boxes. The name parameter is what gets sent back to the server, not the field's ID:
<input type="text" id="sString" name="sString">
and then in PHP
$search = $_GET['sString'];
You need to use attribute name instead of value.
<h3>Search for a Customer</h3>
<form action="search.php" method="get">
<input type="text" id="sString" name="sString"/>
<select name="sField">
<option name="Name">Name</option>
<option name="HostID">Host ID</option>
<option name="OrderNumber">Order Number</option>
<option name="Theme">Theme</option>
</select>
<input type="submit" value="submit"/>
</form>
Try:
<form action="search.php" method="get">
<input type="text" name="sString" id="sString" value="">
<select name="sField">
<option value="Name">Name</option>
<option value="HostID">Host ID</option>
<option value="OrderNumber">Order Number</option>
<option value="Theme">Theme</option>
</select>
<input type="submit" value="submit"/>
</form>
You should be able to access form entered variables by $_GET array in search.php. To see what is going on try var_dump($_GET);
I'm new to PHP, and I can't figure this out.
I'm trying to figure out how to access the data of a group of select boxes I have defined in my HTML code. I tried grouping them as a class, but that doesn't seem to work... maybe I was doing it wrong.
This is the following HTML code.
<form action="" method="post">
<select class="foo">
<option> 1.....100</option>
</select>
<select class="foo">
<option> 1.... 500></option>
</select>
<input type="submit" value="Submit" name="submit"/>
</form>
I essentially want to group all my select boxes and access all the values in my PHP code.
Thanks
Use the name attribute in your select tags. Then you can access those fields by name in the $_POST variable.
<form action="" method="post">
<select name="number_one">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
<select name="number_two">
<option value='a'>1</option>
<option value='b'>2</option>
<option value='c'>3</option>
</select>
<input type="text" name="something"/>
<input type="hidden" name="hidden_value" value="hidden"/>
<input type="submit" value="Submit" name="submit"/>
</form>
In your PHP you can access these like so:
$number_one = $_POST['number_one'];
$number_two = $_POST['number_two'];
$something = $_POST['something'];
$hidden_value = $_POST['hidden_value'];