Check boxes Value Manipulation - php

Below are my static check boxes with values.
What I need is when user Checks any of the check boxes and then click submit I need the checked chec kboxes values in php further i want to place them in mysql query like this
select * from table where "all check boxes values"
My search in mysql will be based on all the checked values
echo "<table border='0'>";
echo "<p>Make a Selection to view details</p>";
echo "<tr><th>Scheme Type</th><th>Scehme Sector</th><th>Area</th><th>Year</th></tr>";
echo "<tr><td><input type='checkbox' name='chkSkills' value='ADP' /> District ADP <br/>";
echo "<input type='checkbox' name='chkSkills' value='cmd'/> CM Directives <br/>";
echo "<input type='checkbox' name='chkSkills' value='tkpp'/> Tameer KPK Program <br/>";
echo "<input type='checkbox' name='chkSkills' value='tbcess' /> Tobacco Cess</td>";
echo "<td><input type='checkbox' name='chkSkills' value='wss' /> Water Supply & Sanitation <br/>";
echo "<input type='checkbox' name='chkSkills' value='road'/> Roads <br/>";
echo "<input type='checkbox' name='chkSkills' value='ccb'/> CCB <br/>";
echo "<input type='checkbox' name='chkSkills' value='health'/> Health <br/>";
echo "<input type='checkbox' name='chkSkills' value='education'/> Education <br/>";
echo "<input type='checkbox' name='chkSkills' value='others' /> Others</td>";
echo "<td><input type='checkbox' name='chkSkills' value='pk77'/> PK-77 <br/>";
echo "<input type='checkbox' name='chkSkills' value='pk78'/> PK-78 <br/>";
echo "<input type='checkbox' name='chkSkills' value='pk79' /> PK-79 </td>";
echo "<td><input type='checkbox' name='chkSkills' value='1112'/> 2011-12 <br/>";
echo "<input type='checkbox' name='chkSkills' value='1011'/> 2010-11 </td></tr>";
echo "<tr><td colspan='4' align='right' style='background-color:white;'><input type='submit' name='devsub' value='Submit' /></td></tr>";
echo "</table>";
Regards

change name = chkSkills[] for each checkbox
and retrieve via $_POST['chkSkills']
Than just do this
foreach($_POST['chkSkills'] as $key => $value){
MYSQL_QUERY
}

use name chkSkills[] and then
use in php
if(count($_POST['chkSkills']) > 0)
{
$checkboxes=implode(',',$_POST['chkSkills']);
}
then
make query
select * from table where cloumnname in($checkboxes)

Related

Label tag is not moving the form structure in line

The label tag has the right syntax however the form structure is not aligned well the way I want it.I also put id as well
echo "<form action='getregister.php' method='post'>";
echo "<fieldset >";
echo "<legend>Register</legend>";
echo "<input type='hidden' name='submitted' id='submitted' value='1'/>";
echo "<label for='First_name'>First Name: </label>";
echo "<input type='text' name='U_fname' id='First_name' value=''><br>";
echo "<label for='Last_name'>Last Name: </label>";
echo "<input type='text' name='U_sname' id='Last_name' value=''><br>";
echo "<label for='Address' >Address: </label>";
echo "<input type='text' name='U_address' id='Address' value=''><br>";
echo "<label for='Postcode' >Postcode: </label>";
echo "<input type='text' name='U_postcode' id='Postcode' value=''><br>";
echo "<label for='Telno' >Tel No: </label>";
echo "<input type='text' name='U_telNo' id='Telno' value=''><br>";
echo "<label for='Email' >Email Address: </label>";
echo "<input type='email' name='U_email' id='Email' value=''><br>";
echo "<label for='password' >Password:</label>";
echo "<input type='password' name='U_password' id='password' value=''><br>";
echo "<label for='passwords' >Confirm Password:</label>";
echo "<input type='password' name='U_confirmPassword' id='passwords' value=''><br>";
echo "<input type='submit' name='Submit' value='Register' />";
echo "<button type='reset' value='Reset'>Clear form</button>";
echo "</fieldset>";
echo "</form>";
Try like this:
echo "<form action='getregister.php' method='post'>";
echo "<fieldset >";
echo "<legend>Register</legend>";
echo "<input type='hidden' name='submitted' id='submitted' value='1'/>";
echo "<table>";
echo "<tr>";
echo "<td><label for='First_name' >First Name: </label></td>";
echo "<td><input type='text' name='U_fname' value=''></td>";
echo "</tr>";
echo "<tr>";
echo "<td><label for='Last_name'>Last Name: </label></td>";
echo "<td><input type='text' name='U_sname' id='Last_name' value=''>";
echo "</tr>";
echo "<table>";
echo "</fieldset>";
echo "</form>";

form - output empty checkboxes (array) in a foreach loop (PHP)

I got a problem & don't get the solutions, hope you can help me!
I created a form which have visitors with optional a guest.
The sense of the form is to delete the visitor and the guest.
Now you got some options:
Delete the visitor and the guest
Delete only the visitor
Delete only the guest
Here are my checkboxes in a while-loop:
while ($row = mysql_fetch_array($result_loeschen))
{
echo "<td class='disable'><input type='text' name='AnmeldungID[]' value=".$row[ID]."></td>";
echo "<input type='hidden' name='option[0]' value='0' />";
echo "<td><input type='checkbox' name='option[0]' value='1' /></td> ";
echo "<input type='hidden' name='option[1]' value='0' />";
echo "<td><input type='checkbox' name='option[1]' value='2' /></td> ";
echo "<input type='hidden' name='option[2]' value='0' />";
echo "<td><input type='checkbox' name='option[2]' value='3' /></td> ";
}
After the form is send:
foreach($_POST['AnmeldungID'] as $key => $ID) {
$option = $_POST['option'][$key];
echo $ID;
echo " = ";
echo $option;
echo "<br />";
}
But it does not work, if all are checked - the output is:
19 = 1
12 = 0
14 = 0
15 = 0
Any ideas?
Thanks!
Chris
You can just set the name to option[] in every checkbox.
Maybe radiobuttons are the better choice for your goal?

HTML form with multiple embedded tables, a lot of white space at top of page

I am having issues with a form I am trying to do in .php
I used tables, within the form, to format how I want the form to look like. The form is working correctly. But when I load the page, there is a huge white space at the top of the page, but I have no idea why it is there. I have tried looking at the source code in the web browser, and there are no html white space characters or anything out of the ordinary. Here is my code:
<?php
$strRequester = $_SERVER['PHP_SELF'];
echo "<div align=center>\n";
echo "<form name='SandwichOrder' action='$strRequester' method='POST'>\n";
####Bread####
echo "<table>\n";
echo "<tr><td bgcolor='CCCCCC'><input type='radio' name='size' value='whole'><b>Whole Sandwich</b></td>\n";
echo "<td bgcolor='CCCCCC'><input type='radio' name='size' value='half'><b>Half Sandwich</b></td></tr>\n";
echo "<tr><td> </td><td> </td></tr>\n";
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Roll/Bread:</b></td><td></td></tr><br>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='whiteroll'>White French Roll</td><br>\n";
echo "<td><input type='radio' name='bread' value='sourroll'>Sour Dough Roll</td><br>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='wheatroll'>Wheat French Roll</td><br>\n";
echo "<td><input type='radio' name='bread' value='dutchcrunch'>Dutch Crunch</td><br>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='nyrye'>New York Rye</td>\n";
echo "<td><input type='radio' name='bread' value='soursliced'>Sour Dough Bread</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='bread' value='wheatsliced'>100% Whole Wheat Bread</td>\n";
echo "</tr>\n";
####Meat####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Meat:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='roastbeef'>Roast Beef</td>\n";
echo "<td><input type='radio' name='meat' value='turkey'>Turkey</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='everroastchicken'>EverRoast Chicken</td>\n";
echo "<td><input type='radio' name='meat' value='ham'>Ham</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='salami'>Salami</td>\n";
echo "<td><input type='radio' name='meat' value='pastrami'>Pastrami</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='tune'>Tuna</td>\n";
echo "<td><input type='radio' name='meat' value='chickensalad'>Chicken Salad\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='meat' value='veggiepatty'>Veggie Patty</td>\n";
echo "<td><input type='radio' name='meat' value='vegetarian'>Vegetarian</td>\n";
echo "</tr>\n";
####Cheese####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Cheese:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='cheddar'>Cheddar Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='swiss'>Swiss Cheese</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='pepperjack'>Pepper Jack Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='american'>American Cheese</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='radio' name='cheese' value='provolone'>Provolone Cheese</td>\n";
echo "<td><input type='radio' name='cheese' value='none'>No Cheese</td>\n";
echo "</tr>\n";
####Condiments####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Your Condiments:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='mayonnaise' value='mayonnaise'>Add Mayonnaise</td>\n";
echo "<td><input type='checkbox' name='mustard' value='mustard'>Add Mustard</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='lettuce' value='lettuce'>Add Lettuce</td>\n";
echo "<td><input type='checkbox' name='pickles' value='pickles'>Add Pickles</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='tomato' value='tomato'>Add Tomato</td>\n";
echo "<td><input type='checkbox' name='peppers' value='peppers'>Add Peppers</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='onion' value='onion'>Add Onion</td>\n";
echo "<td><input type='checkbox' name='olives' value='olives'>Add Olives</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='salt' value='salt'>Add Salt</td>\n";
echo "<td><input type='checkbox' name='suboil' value='suboil'>Add Sub Oil</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='pepper' value='pepper'>Add Pepper</td>\n";
echo "<td><input type='checkbox' name='avocado' value='avocado'>Add Avocado $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='sprouts' value='sprouts'>Add Sprouts $0.50</td>\n";
echo "</tr>\n";
####Extras####
echo "<tr><td bgcolor='CCCCCC'><b>Choose Extra Meat or Cheese:</b></td><td></td></tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eroastbeef' value='eroastbeef'>Extra Roast Beef $1.00</td>\n";
echo "<td><input type='checkbox' name='eturkey' value='eturkey'>Extra Turkey $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eeverroastchicken' value='eeverroastchicken'>Extra EverRoast Chicken $1.00</td>\n";
echo "<td><input type='checkbox' name='eham' value='eham'>Extra Ham $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='esalami' value='esalami'>Extra Salami $1.00</td>\n";
echo "<td><input type='checkbox' name='epastrami' value='epastrami'>Extra Pastrami $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='etuna' value='etuna'>Extra Tuna $1.00</td>\n";
echo "<td><input type='checkbox' name='echickensalad' value='echickensalad'>Extra Chicken Salad $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='ebacon' value='ebacon'>Extra Bacon $1.00</td>\n";
echo "<td><input type='checkbox' name='eveggiepatty' value='eveggiepatty'>Extra Veggie Patty $1.00</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='evegetarian' value='evegetarian'>Extra Vegetarian $1.00</td>\n";
echo "<td><input type='checkbox' name='echeddar' value='echeddar'>Extra Cheddar $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eamerican' value='eamerican'>Extra American $0.50</td>\n";
echo "<td><input type='checkbox' name='eswiss' value='eswiss'>Extra Swiss Cheese $0.50</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type='checkbox' name='eprovolone' value='eprovolone'>Extra Provolone Cheese $0.50</td>\n";
echo "<td><input type='checkbox' name='epepperjack' value='epepperjack'>Extra Pepper Jack Cheese $0.50</td>\n";
echo "</tr>\n";
echo "</table>\n";
####Name/Instructions####
echo "<b>Add your Name or Special Instructions</b><br>\n";
echo "<input type='text' name='instructions' value='' size='50'><br>\n";
echo "<input type='SUBMIT' name='SUBMIT' value='Add to Order'><br>\n";
echo "<input type='button' name='CANCEL' value='Cancel Item'>\n";
echo "</form>";
echo "</div>\n";
?>
I have also tried putting the entire form into a table, but that did not help either. Any suggestions would be great. I am fairly new to .php and html and so I do not even know where to start, in trouble shooting this issue.
Are you echoing the form into an html document? ie
<!doctype html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
YOUR FORM HERE
</body>
</html>
(http://www.w3schools.com/tags/tag_body.asp)
It's likely there is default styling on your div or on the html. In your css try:
html, body {
height: 100%;
width: 100%;
margin: 0;
}
div {
margin: 0;
}

php included form acting strangley with Firefox

For some reason when I call a function to create a form, the drop down menus aren't sticky and the browser forces users to click into the first text field and tab through the rest. It won't let them mouse through the fields. This is only happening in FF, not IE or Chrome. The forms I'm including are just basic html and only php pages I include are doing this.
Here is one function:
function addNoteUI($keyword) {
echo "<div id='search_result_right'>";
echo "<center><div id='enter_note_header'>Assign a Salesperson</div></center><p>";
echo "<form id='response' action='notes_add.php' method='post'>";
echo "<label for='mod_num'>MOD Initials: <label>";
echo "<input type='text' name='mod_num' size='2' maxlength='4'><p>";
echo "<label for='sales_num'>Assigned to Sales Person: <label>";
echo "<input type='text' name='sales_num' size='2' maxlength='4'><p>";
echo "<input type='hidden' name='question_num' value='$keyword'>";
echo "<label for='response'>Note</label><br>";
echo "<textarea name='response' cols='30' rows='7 maxlength='510'></textarea><p>";
echo "<input type='submit' value='Assign'>";
echo "</form>";
echo "</div>";
Here is the other:
function changeDept() {
include 'ask_search.php';
echo "<div id='search_result'>";
echo "<form action='change_dept.php' method='post'>";
echo "<label for='current_num'>Enter the Question Number to be Changed: <label>";
echo "<input type='text' name='current_num' size='4'><p>";
echo "<label for='store'>Select New Store/Department: <label>";
echo "<select name='store'>";
echo "<option>Please Select</option>";
echo "<option value='Albany'>Sales (Albany Store)</option>";
echo "<option value='Saratoga'>Sales (Saratoga Store)</option>";
echo "<option value='Web Sales'>Sales (TaftFurniture.com)</option>";
echo "<option value='Financing'>Financing</option>";
echo "<option value='Customer Service'>Customer Service</option>";
echo "<option value='Delivery'>Delivery</option>";
echo "<option value='HR'>Human Resources</option>";
echo "<option value='Web Contact'>Website Comment</option>";
echo "<input type='submit' value='Change' id='dropdown'>";
echo "</select></form></div>";
}
Thanks in advance.
Your labels are not closing properly:
echo "<label for='mod_num'>MOD Initials: <label>";
Should be:
echo "<label for='mod_num'>MOD Initials: </label>";
Also, in the second example, you have an input inside the select. The input must be outside:
echo "<option value='Web Contact'>Website Comment</option>";
echo "<input type='submit' value='Change' id='dropdown'>";
echo "</select></form></div>";
Should be:
echo "<option value='Web Contact'>Website Comment</option>";
echo "</select>";
echo "<input type='submit' value='Change' id='dropdown'></form></div>";
And another one, you're not closing your P tags:
echo "<input type='text' name='mod_num' size='2' maxlength='4'><p>";
Should be:
echo "<p><input type='text' name='mod_num' size='2' maxlength='4'></p>";
Try to be more careful with your tags. Some browsers are more forgiving about malformed HTML, but others are not.

php issue in passing an array to Paypal

I have an array of variables that I passing to Paypal via . The problem I have is when the Paypal screen loads the items, qty, price section is empty. Here is the code snippet for the passing:- (arrays cart_stock and cart_price hold the data to pass, $tmp_cart_count hold the total number of items to pass)
<?php
echo "<form target='PayPal' action='https://www.sandbox.paypal.com/cgi-bin/webscr' method='post'>";
echo "<input name='cmd' value='_xclick' type='hidden' />";
echo "<input name='upload' value='1' type='hidden' />";
echo "<input name='business' value='sales#danskvintage.com.au' type='hidden' />";
// other irrelevant variables are passed here //
$i=0;$count=1;
while ($i < $tmp_cart_count)
{
echo "<input name='custom' value='".$_SESSION['cart_stock'][$i]."' type='hidden' >";
echo "<input name='item_name_".($count)."' value='".$_SESSION['cart_title'][$i]."' type='hidden' >";
echo "<input name='quantity_".($count)."' value='1' type='hidden' >";
echo "<input name='amount_".($count)."' value='".$_SESSION['cart_price'][$i]."' type='hidden' >";
echo "<input name='shipping_".($count)."' value='0' type='hidden' >";
$i++;
$count++;
}
echo "<input type='submit' value='PayPal'>";
echo "</form>";
?>
Any help would be much appreciated, as it has me stumped.
Try changing
echo "<input name='cmd' value='_xclick' type='hidden' />";
into
echo "<input name='cmd' value='_cart' type='hidden' />";
I believe that might help.

Categories