a,应该在mysqli中设置我的帐户字段,该字段使用值为a,b,c ect的enym字段
b,显示一个包含我的注册表单的div,根据该帐户显示我需要的字段。
我遇到的问题是将数据输入mysqli,其中选择或“选中”单选按钮。表单中的所有其他文件都发布到mysql中,它只是让单选按钮发布它的值。
ok php如下
<?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
?>
我的html
<!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>
在myql中的广告我的表中有一个名为accounttype的字段,正如我所说的那样使用枚举格式这就是行
帐户类型枚举('a','b','c','d','e','f','g'为管理员设置备用
我需要什么才能让所选单选按钮根据无线电值设置帐户类型。我以前几乎没有使用单选按钮,并尝试过一些东西,但它们都失败了。
这里的任何帮助都是天赐之物
编辑以显示所有代码
答案 0 :(得分:1)
1)您必须有一个表单 - 您没有与第一个表单相关联的任何操作 - 这些单选按钮应该在具有相关操作的表单内(php文件)。 action =“”表示它由当前页面处理 - 实际上没有进行任何处理。
2)您确实为所有单选按钮保留了相同的名称。
3)您将该名称设置为“accounttype”,因为这是您用来分配值的名称。 (你不需要任何preg_replace)。
4)通过mysql_real_escape_string运行所有数据,而不仅仅是电子邮件。
答案 1 :(得分:0)
如果您使用任何库(jquery),您可以轻松完成此操作。
(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);
答案 2 :(得分:0)
<input type="radio" name="luckynumber" value="1" />
<input type="radio" name="luckynumber" value="2" />
在php中
print_r($_POST['luckynumber']);