Html Form:
<form>
<select name="country[]" id="country" multiple>
<option value="any">any</option>
<option value="India">India</option>
<option value="Canada">Canada</option>
<option value="UK">UK</option>
<option value="USA">USA</option>
<option value="Australia">Australia</option>
</select>
</form>
PHP Code
<?php
$country = $_REQUEST['country'];
if($country=="")
$countrysql = "";
else
{
if($country == "Any") $countrysql = "";
else
{
$country = str_replace(",","','",$country);
$countrysql = " and Country in ('$country')";
}
}
$queryString = "SELECT * FROM register where $countrysql";
?>
I have created a form in PHP and I want to search multiple options. I already created table Register and a column Country. I am getting the result If I give single value. If I give multiple I am not getting the result. Please help.
You evaluate in if($country == "Any") the word Any is not equal to any in option <option value="any">any</option>
But I suggest this php code:
<?php
$country="";
$countryError="";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["country"])){
$countryError = "Country is required";
}else{
$country = $_POST["country"];
}
if($country == "Any") {
$queryString = "SELECT * FROM register";
}else{
$queryString = "SELECT * FROM register where Country in ('$country')";
}
// Print the SQL string:
echo $queryString;
}
?>
The html tags:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<select name="country" id="country" multiple>
<option value="Any">any</option>
<option value="India">India</option>
<option value="Canada">Canada</option>
<option value="UK">UK</option>
<option value="USA">USA</option>
<option value="Australia">Australia</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<span class="error"><?php echo $countryError;?></span>
this is my code in the first page
<?php
session_start();
$fullname = $_SESSION['fullname'];
$success_page = './chart.php';
if(isset($_POST['Button1'])) {
$_SESSION['month'] = $_POST['Combobox1'];
$_SESSION['year'] = $_POST['Combobox2'];
header('Location: '.$success_page);
}
?>
And this is my 2nd page
session_start();
$fullname = $_SESSION['fullname'];
$month = $_SESSION['month'];
$year = $_SESSION['year'];
echo $month;
echo $year;
echo $fullname;
There are 2 combobox in my 1st page and or some reason I'm not able to echo the month and year in my 2nd page. Thanks for the help!
EDIT: this is the html part with my form
<select name="Combobox1" size="1" id="Combobox1" style="position:absolute;left:550px;top:580px;width:250px;height:50px;z- index:1;">
<option value="1">Janvier</option>
<option value="2">Février</option>
<option value="3">Mars</option>
<option value="4">Avril</option>
<option value="5">Mai</option>
<option value="6">Juin</option>
<option value="7">Juillet</option>
<option value="8">Août</option>
<option value="9">Septembre</option>
<option value="10">Octobre</option>
<option value="11">Novembre</option>
<option value="12">Décembre</option>
</select>
<select name="Combobox2" size="1" id="Combobox2" style="position:absolute;left:900px;top:580px;width:250px;height:50px;z-index:1;">
<option>2014</option>
<option>2015</option>
<form method='post' action='mois.php' enctype='multipart/form-data'>
<input type="submit" id="Button1" name="Button1" value="Submit" style="position:absolute;left:800px;top:700px;width:96px;height:25px;z-index:2;">
</form>
Hey i am having some trouble getting an options[] array to work, if anyone can help that will be great
Form
<form method="post" action="array2.php">
<select name="options[]">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input name="submit" type="submit" value="submit">
</form>
The array2.php
<?php
session_start();
if(isset($_POST['submit'])){
if($_POST['options[]'] == "" ){
header("Location: error.html");
exit;
}else{
$checked = $_POST['options'];
$_SESSION['checked'] = $checked;
}
}
?>
Any help would be great, also what happens is even if it's an empty feild, the thing progress's to the rest of the script
rest of script
<?php
for($i=0; $i < count($checked); $i++){
echo "You have selected to recive " . $checked[$i] . " tickets<br/>";
}
for($i=0; $i < count($checked2); $i++){
echo "And you have selected to recive " . $checked2[$i] . " for accommodation are you sure? <br/>";
}
?>
Sorry I am unable to reply to people for now soon as I posted it a class came to the empty room so need to wait an hour :/
You need the change your options[] to option as it mean you are submitting multiple select with the same name
<form method="post" action="array2.php">
<select name="options">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input name="submit" type="submit" value="submit">
</form>
in your array2.php file
<?php
session_start();
if(isset($_POST['submit'])){
if($_POST['options'] == "" ){
header("Location: error.html");
exit;
}else{
$checked = $_POST['options'];
$_SESSION['checked'] = $checked;
}
}
?>
if you really need to send options[]
<?php
session_start();
if(isset($_POST['submit'])){
if(is_array($_POST['options']){
if($_POST['options'][0] == "" ){
header("Location: error.html");
exit;
}else{
$checked = $_POST['options'][0];
$_SESSION['checked'] = $checked;
}
}else{
if($_POST['options'] == "" ){
header("Location: error.html");
exit;
}else{
$checked = $_POST['options'];
$_SESSION['checked'] = $checked;
}
}
}
?>
you can clean this if else as you like
You can use this example code
<?php
if($_POST) {
if(isset($_POST['state'])) {
if($_POST['state'] == 'NULL') {
echo '<p>Please select an option from the select box.</p>';
}
else {
echo '<p>You have selected: <strong>', $_POST['state'], '</strong>.</p>';
}
}
}
?>
and your html code
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<fieldset>
<legend>Please select a state</legend>
<select name="state">
<option value="NULL">-- Please select a state --</option>
<option value="AK">AK - Alaska</option>
<option value="AL">AL - Alabama</option>
<option value="WY">WY - Wyoming</option>
</select>
<input type="submit" name="submit">
</fieldset>
</form>
in your case options[] can be used for sending multiple fields as array, the index starts with 0, for example:
<input name="test[]"> : index 0
<input name="test[]"> : index 1
then, you can get these values in $_POST['test'] like this:
$input_one = $_POST['test'][0];
$input_one = $_POST['test'][1];
if you look at this inside $_POST it will be like this:
$_POST = array (
...,
'test' => array(0=> ..., 1 => ...)
)
for your form, if you only had one options[], then the value is the $_POST will be
if(isset($_POST['options'][0])){
}
So let's clean it up
<select name="options">
You do not need options[].
And then the result of $_POST['options'] will be the value of option. And add there <option value="0">Select</option> and then check whether the POSTed data is higher then 0
in html
<select name="options">
<option value="0"></option>
<option value="1">1</option>
.
.
in php
if(isset($_POST['options']) && !empty($_POST['options'])) {
$checked = $_POST['options'];
}
Once submitted selected option, the data is not stored.
just want to know how to post back the data if validation fails
The following line doesnt really work for me.
<select id="numbers" name="numbers" value="<?php echo (isset($_POST['numbers'])) ? $_POST['numbers'] : " "; ?>"/>
if someone could give me a hand?
Many thanks, here is my code
<?php
if(isset($_POST['numbers']) &&($_POST['fruits']) && $_POST['numbers'] != "null" && $_POST['fruits'] !== "null")
{
echo "Thank you!";
} elseif (isset($_POST['numbers']) && $_POST['numbers'] = "null") {
echo "you forgot to choose a number";
}
elseif(isset($_POST['fruits']) && $_POST['fruits'] = "null")
{
echo "you forgot to choose fruit name";
}
?>
<form id="form" name="form" method="post" action="">
<label for="expiry">Select</label>
<select id="numbers" name="numbers" value="<?php echo (isset($_POST['numbers'])) ? $_POST['numbers'] : " "; ?>"/>
<option value="null" selected="selected">-</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
</select>
<select id="fruits" name="fruits" value="<?php echo (isset($_POST['fruits']))? $_POST['fruits'] : ''; ?>"/>
<option value="null" selected="selected">-</option>
<option value="Apple">Apple</option>
<option value="Banana">Banana</option>
<option value="Pear">Pear</option>
</select>
<input type="submit" value="Send" />
</form>
Solved it, Maybe not a best way, but at least got it sorted:
<?php
$item = null; #
$itemyear = null;
if(isset($_POST['numbers'])){
$item = $_POST['numbers'];
}
if(isset($_POST['fruits'])){
$itemyear = $_POST['fruits'];
}
if(isset($item) && isset($itemyear) && $item != "null" && $itemyear !== "null")
{
echo "Thank you!";
} elseif ($item == "null") {
echo "you forgot to choose a number";
}
elseif($itemyear == "null")
{
echo "you forgot to choose fruit name";
}
?>
<form id="form" name="form" method="post" action="">
<label for="expiry">Select</label>
<select id="numbers" name="numbers" />
<option value="null" selected="selected">-</option>
<option value="01" <?php if($item == '01'): echo "selected='selected'"; endif; ?>>01</option>
<option value="02" <?php if($item == '02'): echo "selected='selected'"; endif; ?>>02</option>
<option value="03" <?php if($item == '03'): echo "selected='selected'"; endif; ?>>03</option>
</select>
<select id="fruits" name="fruits" />
<option value="null" selected="selected">-</option>
<option value="Apple"<?php if($itemyear == 'Apple'): echo "selected='selected'"; endif; ?> >Apple</option>
<option value="Banana"<?php if($itemyear == 'Banana'): echo "selected='selected'"; endif; ?>>Banana</option>
<option value="Pear"<?php if($itemyear == 'Pear'): echo "selected='selected'"; endif; ?>>Pear</option>
</select>
<input type="submit" value="Send" />
</form>
<?php
echo $item ."-". $itemyear;
?>
the PHP isset() function returns either true or false (depending on whether the input is.. well... set.
You would want to use this:
value='<?php echo (isset($_POST['numbers'])) ? $_POST['numbers'] : ""; ?>
You can't set a value attribute on a <select>. You have to find the correct <option> and set its selected attribute. Personally, I put a data-default attribute on the <select> and then use JavaScript to loop through the options and find the right one.
Oh now I see.
I don't know what the usual thing to do is but one way is to put all the data as a query string when you redirect the user back. The reason why it doesn't stay in the $_POST global is because it's only kept on the page you post to then it's gone.
So when you redirect the user back
if(validationFailed)
{
header("Location: page.php?data=example");
}
The data can then be retrieved in page.php by using
$data = $_GET['data']; // contains "example"
hey guys need to pick your brains, i currently have a form set up that uses 6 radio buttons which do 2 things.
a, is supposed to set my account field in mysqli which uses a enym field with the values of a,b,c ect
b, shows a div that includes my resgistration form showing the fields i need based on the account.
the problem i have faced is getting the the data into mysqli of which radio button is selected or "checked". all the other fileds in the form post into mysql fine its just getting the radio button to post its value.
ok php is as follows
<?php
$errorMsg = "";
// First we check to see if the form has been submitted
if (isset($_POST['firstname'])){
//Connect to the database through our include
include_once "connect_to_mysql.php";
// Filter the posted variables
$username = preg_replace("[^A-Za-z0-9]", "", $_POST['username']); // filter everything but numbers and letters
$firstname = preg_replace("[^A-Za-z]", "", $_POST['firstname']); // filter everything but letters
$surname = preg_replace("[^A-Za-z]", "", $_POST['surname']); // filter everything but letters
$accounttype = preg_replace("[^a-z]", "", $_POST['accounttype']); // filter everything but lowercase letters
$b_m = preg_replace('#[^0-9]#i', '', $_POST['birth_month']); // filter everything but numbers
$b_d = preg_replace('#[^0-9]#i', '', $_POST['birth_day']); // filter everything but numbers
$b_y = preg_replace('#[^0-9]#i', '', $_POST['birth_year']); // filter everything but numbers
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = preg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
$pf = preg_replace("[^a-z]", "", $_POST['pf']);
$sa = preg_replace("[^a-z]", "", $_POST['sa']);
$ba = preg_replace("[^a-z]", "", $_POST['ba']);
$ve = preg_replace("[^a-z]", "", $_POST['be']);
$bu = preg_replace("[^a-z]", "", $_POST['bu']);
$se = preg_replace("[^a-z]", "", $_POST['se']);
// Check to see if the user filled all fields with
// the "Required"(*) symbol next to them in the join form
// and print out to them what they have forgotten to put in
if((!$username) || (!$firstname) || (!$surname) || (!$accounttype) || (!$b_m) || (!$b_d) || (!$b_y) || (!$email) || (!$password)){
$errorMsg = "You did not submit the following required information!<br /><br />";
if(!$username){
$errorMsg .= "--- User Name";
} else if(!$accounttype){
$errorMsg .= "--- Account Type";
} else if(!$b_m){
$errorMsg .= "--- Birth Month";
} else if(!$b_d){
$errorMsg .= "--- Birth Day";
} else if(!$b_y){
$errorMsg .= "--- Birth year";
} else if(!$firstname){
$errorMsg .= "--- First Name";
} else if(!$surname){
$errorMsg .= "--- Surname";
} else if(!$email){
$errorMsg .= "--- Email Address";
} else if(!$password){
$errorMsg .= "--- Password";
}
} else {
// Database duplicate Fields Check
$sql_username_check = mysql_query("SELECT id FROM memberstable WHERE username='$username' LIMIT 1");
$sql_email_check = mysql_query("SELECT id FROM memberstable WHERE email='$email' LIMIT 1");
$username_check = mysql_num_rows($sql_username_check);
$email_check = mysql_num_rows($sql_email_check);
if ($username_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your User Name is already in use inside our system. Please try another.";
} else if($email_check > 0){
$errorMsg = "<u>ERROR:</u><br />Your Email address is already in use inside our system. Please try another.";
} else {
// Add MD5 Hash to the password variable
$hashedPass = md5($password);
// Convert Birthday to a DATE field type format(YYYY-MM-DD) out of the month, day, and year supplied
$full_birthday = "$b_y-$b_m-$b_d";
// Add user info into the database table, claim your fields then values
$sql = mysql_query("INSERT INTO memberstable (username, firstname, surname, accounttype, email, birthday, password)
VALUES('$username','$firstname','$surname','$accounttype','$email','$full_birthday','$hashedPass')") or die (mysql_error());
// Get the inserted ID here to use in the activation email
$id = mysql_insert_id();
// Create directory(folder) to hold each user files(pics, MP3s, etc.)
mkdir("memberFiles/$id", 0755);
// Start assembly of Email Member the activation link
$to = "$email";
// Change this to your site admin email
$from = "admin#getscene.com";
$subject = "Complete your registration";
//Begin HTML Email Message where you need to change the activation URL inside
$message = '<html>
<body bgcolor="#FFFFFF">
Hi ' . $firstname . ',
<br /><br />
You must complete this step to activate your account with us.
<br /><br />
Please click here to activate now >>
<a href="http://www.getscene.com/activation.php?id=' . $id . '">
ACTIVATE NOW</a>
<br /><br />
Your Login Data is as follows:
<br /><br />
E-mail Address: ' . $email . ' <br />
Password: ' . $password . '
<br /><br />
Thanks!
</body>
</html>';
// end of message
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
$to = "$to";
// Finally send the activation email to the member
mail($to, $subject, $message, $headers);
// Then print a message to the browser for the joiner
header( 'Location: http://localhost/urshow/registrationsuccess.php' ) ;
// Exit so the form and page does not display, just this success message
} // Close else after database duplicate field value checks
} // Close else after missing vars check
} //Close if $_POST
?>
for the html i have
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Getscene registration</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.7.1.min.js" type="text/javascript"></script>
</script>
</head>
<body>
<?php include_once "header_template.php"; ?>
<style type="text/css">
#account_types > div { display: none; }
</style>
<div id="signupwrapper">
<div id="signupinner">
<h3 align="left"> GETSCENE REGISTRATION ! </h3>
<hr />
<div id="signup" style="border:thin; border-color:#666">
<h4 align="left">Please Choose One of The Following Account Types</h4>
<div id="accountswrapper">
<form id="accountchoice" name="accountchoice" method="post" action="">
<label for="personalfan">personal/fan</label>
<input type="radio" name="pf" id="personalfan" value="radio1" checked="checked" />
<label for="soloartist">Solo artist</label>
<input type="radio" name="sa" id="soloartist" value="radio2" />
<label for="band">band</label>
<input type="radio" name="ba" id="band" value="radio3" />
<label for="venue">venue</label>
<input type="radio" name="ve" id="venue" value="radio4" />
<label for="business">business</label>
<input type="radio" name="bu" id="business" value="radio5" />
<label for="service">service</label>
<input type="radio" name="se" id="service" value="radio6" />
</form>
<hr />
<div id="account_types">
<div class="personalfan">
<table width="400" border="0" align="center">
<form action="regpersonal.php" method="post" enctype="multipart/form-data">
<tr>
<td colspan="2"><?php echo "$errorMsg"; ?></td>
</tr>
<tr>
<td><div align="right">Username:</div></td>
<td><label for="username"></label>
<input name="username" type="text" id="username" size="30" /></td>
</tr>
<tr>
<td width="146"><div align="right">First Name:</div></td>
<td width="244"><label for="firstname"></label>
<input name="firstname" type="text" id="firstname" size="30" /></td>
</tr>
<tr>
<td><div align="right">Surname:</div></td>
<td><label for="surname"></label>
<input name="surname" type="text" id="surname" size="30" /></td>
</tr>
<tr>
<td><div align="right">Email Address:</div></td>
<td><label for="email"></label>
<input name="email" type="text" id="email" size="30" /></td>
</tr>
<tr>
<td><div align="right">Password:</div></td>
<td><label for="password"></label>
<input name="password" type="password" id="password" size="30" /></td>
</tr>
<tr>
<td><div align="right">Date Of Birth:</div></td>
<td>
<select name="birth_day" class="formFields" id="birth_day">
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
<option value='04'>04</option>
<option value='05'>05</option>
<option value='06'>06</option>
<option value='07'>07</option>
<option value='08'>08</option>
<option value='09'>09</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
<select name="birth_month" class="formFields" id="birth_month">
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
<option value='04'>April</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>August</option>
<option value='09'>September</option>
<option value='10'>October</option>
<option value='11'>November</option>
<option value='12'>December</option>
</select>
<select name="birth_year" class="formFields" id="birth_year">
<option value='2012'>2012</option>
<option value='2011'>2011</option>
<option value='2010'>2010</option>
<option value='2009'>2009</option>
<option value='2008'>2008</option>
<option value='2007'>2007</option>
<option value='2006'>2006</option>
<option value='2005'>2005</option>
<option value='2004'>2004</option>
<option value='2003'>2003</option>
<option value='2002'>2002</option>
<option value='2001'>2001</option>
<option value='2000'>2000</option>
<option value='1999'>1999</option>
<option value='1998'>1998</option>
<option value='1997'>1997</option>
<option value='1996'>1996</option>
<option value='1995'>1995</option>
<option value='1994'>1994</option>
<option value='1993'>1993</option>
<option value='1992'>1992</option>
<option value='1991'>1991</option>
<option value='1990'>1990</option>
<option value='1989'>1989</option>
<option value='1988'>1988</option>
<option value='1987'>1987</option>
<option value='1986'>1986</option>
<option value='1985'>1985</option>
<option value='1984'>1984</option>
<option value='1983'>1983</option>
<option value='1982'>1982</option>
<option value='1981'>1981</option>
<option value='1980'>1980</option>
<option value='1979'>1979</option>
<option value='1978'>1978</option>
<option value='1977'>1977</option>
<option value='1976'>1976</option>
<option value='1975'>1975</option>
<option value='1974'>1974</option>
<option value='1973'>1973</option>
<option value='1972'>1972</option>
<option value='1971'>1971</option>
<option value='1970'>1970</option>
<option value='1969'>1969</option>
<option value='1968'>1968</option>
<option value='1967'>1967</option>
<option value='1966'>1966</option>
<option value='1965'>1965</option>
<option value='1964'>1964</option>
<option value='1963'>1963</option>
<option value='1962'>1962</option>
<option value='1961'>1961</option>
<option value='1960'>1960</option>
<option value='1959'>1959</option>
<option value='1958'>1958</option>
<option value='1957'>1957</option>
<option value='1956'>1956</option>
<option value='1955'>1955</option>
<option value='1954'>1954</option>
<option value='1953'>1953</option>
<option value='1952'>1952</option>
<option value='1951'>1951</option>
<option value='1950'>1950</option>
<option value='1949'>1949</option>
<option value='1948'>1948</option>
<option value='1947'>1947</option>
<option value='1946'>1946</option>
<option value='1945'>1945</option>
<option value='1944'>1944</option>
<option value='1943'>1943</option>
<option value='1942'>1942</option>
<option value='1941'>1941</option>
<option value='1940'>1940</option>
<option value='1939'>1939</option>
<option value='1938'>1938</option>
<option value='1937'>1937</option>
<option value='1936'>1936</option>
<option value='1935'>1935</option>
<option value='1934'>1934</option>
<option value='1933'>1933</option>
<option value='1932'>1932</option>
<option value='1931'>1931</option>
<option value='1930'>1930</option>
<option value='1929'>1929</option>
<option value='1928'>1928</option>
<option value='1927'>1927</option>
<option value='1926'>1926</option>
<option value='1925'>1925</option>
<option value='1924'>1924</option>
<option value='1923'>1923</option>
<option value='1922'>1922</option>
<option value='1921'>1921</option>
<option value='1920'>1920</option>
<option value='1919'>1919</option>
<option value='1918'>1918</option>
<option value='1917'>1917</option>
<option value='1916'>1916</option>
<option value='1915'>1915</option>
<option value='1914'>1914</option>
<option value='1913'>1913</option>
<option value='1912'>1912</option>
<option value='1911'>1911</option>
<option value='1910'>1910</option>
<option value='1909'>1909</option>
<option value='1908'>1908</option>
<option value='1907'>1907</option>
<option value='1906'>1906</option>
<option value='1905'>1905</option>
<option value='1904'>1904</option>
<option value='1903'>1903</option>
<option value='1902'>1902</option>
<option value='1901'>1901</option>
<option value='1900'>1900</option>
</select></td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</form>
</table></div>
<div class ="soloartist"></div>
<div class="band"></div>
<div class="venue"></div>
<div class="business"></div>
<div class="service"></div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#accountchoice').change(function() {
var divToShow = $(this).find('input:checked').attr('id');
$('#account_types > div').each(function() {
if($(this).hasClass(divToShow)) { $(this).show(); }
else { $(this).hide();}
});
});
$('#accountchoice').trigger('change');
});
</script>
<?php include_once "footer_template.php"; ?>
</body>
</html>
ad in mysql my table has a field called accounttype, which as i said uses an enum format this is the row
accounttype enum('a', 'b', 'c', 'd', 'e', 'f', 'g' one set spare for admin
what would i need for php to get the selected radio button to set account type based on the radios value. i have little to no previous use of radio buttons and have tried a few things but they all fail.
any help here would be a godsend
edited to show all code
1) You have to have one form - you don't have any action associated with the first form - those radio buttons should be within the form that has an action associated (php file). action="" means it's processed by current page - which actually doesn't do any processing.
2) You do keep THE SAME name for all radio buttons.
3) You make that name 'accounttype' as that's what you use to assign a value. (and you don't need any preg_replace there).
4) Run all of your data through mysql_real_escape_string, not just the email.
if you are using any library (jquery) you can do this easily.
(function($){
$('#accountchoice').find('input').change(function(){
if(this.checked){
if($(this).val() == 'radio1'){
// do the needed ajax for radio1 is selected
}
// add conditions for all the radio buttons here, or you can use a swicth case too.
}
});
})(jQuery);
<input type="radio" name="luckynumber" value="1" />
<input type="radio" name="luckynumber" value="2" />
In php
print_r($_POST['luckynumber']);