I am working on my project I want to store my multiple selected option value in the database but when I select more than one option at one time that time my only last selected values stored in DB please help my where am I am wrong?
Here is my Code:
<?php
require_once('contact_fun.php');
require_once('contact_banner_fun.php');
$obj = new contact_banner();
$crud = new contact_us();
$banner = $obj->get_data_banner();
if(!$banner){
echo "No Banner";
exit;}
$path = 'http://localhost/THE_VELVET_WALK/contact/';
$result = $crud->getData("SELECT * FROM tb_contactus");
foreach ($result as $res) {
$id = $res['id'];
$name = $res['name'];
$business = $res['business'];
$email = $res['email'];
$phone = $res['phone'];
$message = $res['message'];
$style = $res['style'];
}
if(isset($_POST['submit']))
{
$name = $crud->escape_string($_POST['name']);
$business = $crud->escape_string($_POST['business']);
$email = $crud->escape_string($_POST['email']);
$phone = $crud->escape_string($_POST['phone']);
$message = $crud->escape_string($_POST['message']);
$style = $crud->escape_string($_POST['style']);
$result = $crud->execute(" INSERT INTO tb_contactus(name, business, email,
phone, message, style, update_dt)VALUES ('$name','$business', '$email',
'$phone', '$message', '$style', now())");
}?>
<form action="" method="POST">
<input id="00N7F000001F2j6" name="name" maxlength="40" type="text"
class="materialize-input">
<input id="company" name="business" maxlength="40" type="text"
class="materialize-input">
<input id="email" name="email" maxlength="40" type="email"
class="materialize-input">
<input id="phone" name="phone" maxlength="40" type="text" maxlength="40"
class="materialize-input">
<select multiple id="00N7F000001F2kO" name="style" multiple="multiple" >
<option name="consulting" name="styling" value=""selected disabled>image
consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
</form>
you have to specify in the name of the select that it will be an array like :
<select multiple id="00N7F000001F2kO" name="style[]" multiple="multiple" >
<option value=""selected disabled>image consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
and then you can implode it if you want a string like this
implode(',',$_POST['style']);
EDIT :
change this
$style = $crud->escape_string($_POST['style']);
to
$style = $crud->escape_string(implode(',',$_POST['style']));
you need to use an array for multiple select options :
<select multiple id="00N7F000001F2kO" name="style[]" multiple="multiple" >
<option name="consulting" name="styling" value=""selected disabled>image
consulting</option>
<option value="1">styling</option>
<option value="2">hair & make-up</option>
<option value="3">designing clothes</option>
<option value="4">wedding makeover</option>
<option value="5">personal shopper</option>
<option value="6">corporate services</option>
</select>
this is how tou get the data into your database :
.php
if(isset($_POST['styling']) && !empty($_POST['styling'])){
$Col1_Array = $_POST['styling'];
print_r($Col1_Array);
foreach($Col1_Array as $selectValue){
//show selected
echo $selectValue."<br>";
}
}
Related
So as of now, i can successfully get the results to move from page one to page two using post and get, but no matter what im doing it will not move the info to the 3rd page. Im trying to switch it over to sessions after reading its made exactly for this but for some reason im doing something wrong and after hours of searching i cant for the life of me figure out what it is. I've followed guides, followed videos, and other post related to the topic on this website. I have now come to the conclusion that it is just me and i need some assistance. Any help would be greatly appreciated.
Page 1 (Index Page | Input Your Variables):
<?php session_start();
$_GET['q'] = $q;
$_GET['s'] = $s;
?>
<form action="search.php" method="get">
<input name="q" maxlength="8" type="text" placeholder="License Plate" id="textbox" required />
<select name="s" id="s" required aria-required="true">
<option value="" disabled selected>CHOOSE STATE</option>
<option value="AL">ALABAMA</option>
<option value="AK">ALASKA</option>
<option value="AZ">ARIZONA</option>
<option value="AR">ARKANSAS</option>
<option value="CA">CALIFORNIA</option>
<option value="CO">COLORADO</option>
<option value="CT">CONNECTICUT</option>
etc...
</select>
<input type="submit" value="SEARCH" id="submitbtn"></form>
Page 2 (Search.php that will take you directly to page specified if its already been created):
<?php session_start();
$q = $_POST['q'];
$s = $_POST['s'];
?>
<?php
$dir = 'states';
$s = (isset($_GET['s']))? strtolower($_POST['s']) : '';
$q = (isset($_GET['q']))? strtoupper($_POST['q']) : '';
$res = opendir($dir);
while(false!== ($file = readdir($res))) {
if(strpos(strtoupper($file),$q)!== false &&!in_array($file)) {
echo "<a href='$dir/$s/$q.htm'>$file</a>";
}
}
closedir($res);
?>
<?php
echo $htmlHeader;
while($stuff){
echo $stuff;
}
echo "<script>window.location =
'http://www.somesite.com/$dir/$s/$q.htm'</script>";
?>
Page 3 (404 page for catch all that are not in the system):
<?php session_start();
?>
<form action="" method="" name="FormChoice">
<input name="q" maxlength="8" type="text" value="<?php echo $_POST['q']; ?>" id="q" required>
<select name="s" id="s" required aria-required="true">
<option value="" disabled>CHOOSE STATE</option>
<option value="AL" <?php if($_POST['s'] == al) {echo ' selected="selected"';} ?>>ALABAMA</option>
<option value="AK" <?php if($_POST['s'] == ak) {echo ' selected="selected"';} ?>>ALASKA</option>
<option value="AZ" <?php if($_POST['s'] == az) {echo ' selected="selected"';} ?>>ARIZONA</option>
<option value="AR" <?php if($_POST['s'] == ar) {echo ' selected="selected"';} ?>>ARKANSAS</option>
<option value="CA" <?php if($_POST['s'] == ca) {echo ' selected="selected"';} ?>>CALIFORNIA</option>
<option value="CO" <?php if($_POST['s'] == co) {echo ' selected="selected"';} ?>>COLORADO</option>
<option value="CT" <?php if($_POST['s'] == ct) {echo ' selected="selected"';} ?>>CONNECTICUT</option>
</select>
<input type="submit" id="submitbtn2" value="SEARCH" name="submit" OnClick="search()" />
<span id="or">OR</span>
<input type="submit" id="addbtn" value="ADD" name="submit" OnClick="add()" />
</form>
page1
<?php
session_start();
// next 2 lines do NOTHING remove them
// as you have not yet loaded any values into $q and $s
//$_GET['q'] = $q;
//$_GET['s'] = $s;
?>
<form action="search.php" method="get">
<input name="q" maxlength="8" type="text" placeholder="License Plate" id="textbox" required />
<select name="s" id="s" required aria-required="true">
<option value="" disabled selected>CHOOSE STATE</option>
<option value="AL">ALABAMA</option>
<option value="AK">ALASKA</option>
<option value="AZ">ARIZONA</option>
<option value="AR">ARKANSAS</option>
<option value="CA">CALIFORNIA</option>
<option value="CO">COLORADO</option>
<option value="CT">CONNECTICUT</option>
etc...
</select>
<input type="submit" value="SEARCH" id="submitbtn"></form>
Page 2 - Search - receives data from previous form
- Contains lots of unecessary <?php...?>
- Previous form uses method="get" so data will arrive in the $_GET array not the $_POST array
<?php
session_start();
//$q = $_POST['q'];
//$s = $_POST['s'];
// But this is silly as you have not yet tested these values exist
// but you do that in the next lines
//$q = $_GET['q'];
//$s = $_GET['s'];
$dir = 'states';
$s = (isset($_GET['s']))? strtolower($_POST['s']) : '';
$q = (isset($_GET['q']))? strtoupper($_POST['q']) : '';
$res = opendir($dir);
// Now if you want to pass the values of `q` and `s` on to the next form
// they now need to be added to the session
$_SESSION['q'] = $q;
$_SESSION['s'] = $s;
while(false!== ($file = readdir($res))) {
if(strpos(strtoupper($file),$q)!== false &&!in_array($file)) {
echo "<a href='$dir/$s/$q.htm'>$file</a>";
}
}
closedir($res);
echo $htmlHeader;
while($stuff){
echo $stuff;
}
echo "<script>
window.location = 'http://www.somesite.com/$dir/$s/$q.htm';
</script>";
// added missing semi colon ^
?>
Page 3 (404 page for catch all that are not in the system):
Now the data will be available in the SESSION, when you get to this page.
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>
When running this code in the web page I do not get a confirmation that it is complete. I took the sql code directly from phpmyadmin sql query window. I would like a little help to this issue. it effects all the add pages.
id
$results=mysqli_query($con, "select * from Users where `userName` ='$userName'");
$row = mysqli_fetch_array($results);
$id = $row['id_cust'];
that is before this statement
php
if(isset($_POST['insert'])){
$artist = $_POST['artist'];
$place = $_POST['place'];
$hour = $_POST['hour'];
$minute = $_POST['min'];
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$price = $_POST['price'];
$open = $_POST['open'];
$time = $hour.':'.$minute;
$date = $year.'-'.$month.'-'.$day;
$result=mysqli_query($con,"insert into Concert values('$id','$artist','$date','$time','$place','$price','$open')");
if($result)
{
echo 'Values updated successfully';
}
}
html
<form name="addconcerts" method="post" action="addconcert.php" id="form">
<p>Please Fill out all information</p>
Artist:<input type="text" name="artist" /> <br />
Place:<input type="text" name="place" /><br />
Approximant start time<select name="hour">
<option value="">Hour</option>
<option value="01">01</option>
""""""""
<option value="24">24</option>
</select>
<select name="min">
<option value="">Minute</option>
<option value="00">00</option>
<option value="15">15</option>
<option value="30">30</option>
<option value="45">35</option>
</select><br />
<select name="month">
<option value="">Month</option>
<option value = "01">January</option>
""""""""""""""""
<option value = "12">December</option>
</select>
<select name="day">
<option value="">Day</option>
<option value="01">01</option>
""""""""""""""""""
<option value="31">31</option>
</select>
<select name="year">
<option value="">Year</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
</select><br />
Price:<input type="text" name="price"><br />
Opening Act:<input type="text" name="open"><br><br>
<input type="reset" name="reset" value="Reset">
<input type="submit" name="insert" value="insert">
</form>
any help would be greatly appreciated.
Check Your Insert Query.
This is your Insert Query:
$result=mysqli_query($con,"insert into Concert values('$id','$artist','$date','$time','$place','$price','$open')");
And your Insert Query should look like this:
$result=mysqli_query($con,"insert into Concert (id, artist, date, time, place, price, open) values('$id','$artist','$date','$time','$place','$price','$open')");
Of course, you should REPLACE the necessary column names on the above provided code.
The $id variable is not declared. If PRIMARY_KEY and AUTO_INCREMENT, remove the variable.
$result = mysqli_query($con,"insert into Concert (id, artist, date, time, place, price, open) VALUES('$id','$artist','$date','$time','$place','$price','$open')");
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']);
Am not sure how to ask this question but for most of you more experienced php programmers this is going to sound trivial... So I have successfully set up a register and login system and also an admin section where the administrator can see all the users that are currently registered. What I am wanting is for the admin to be able to edit the user's details, and also have the capability to delete/block them. Actually I have just successfully implemented a delete function.
This code here is of the page where the admin can see the users:
<?php
require('admin_sessions.php');
require("../includes/dbconnect.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Admin - iTrade Users Details</title>
<meta name="robots" content="NOFOLLOW,NOINDEX">
<link rel="stylesheet" href="../stylesheet.css" type="text/css">
<!--[if IE 7]>
<link rel="stylesheet" href="../ie7.css" type="text/css">
<script type="text/javascript">
document.createElement('nav');
document.createElement('article');
document.createElement('aside');
document.createElement('header');
document.createElement('footer');
</script>
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="../ie8.css" type="text/css">
<script type="text/javascript">
document.createElement('nav');
document.createElement('article');
document.createElement('aside');
document.createElement('header');
document.createElement('footer');
</script>
<![endif]-->
<style type="text/css">
table{
border:1px solid black;
width:2508px;
}
table th{
border-bottom:1px solid black;
border-left:1px solid black;
border-top:1px solid black;
border-right:1px solid black;
}
.header_tables{
background-color:black;
color:white;
text-align:center
}
</style>
</head>
<body>
<header style="width:2570px;"><span class="header_img"><img src="../img/itradeheader.png" width="465" height="200" alt="iTrade - The Leading Online Trading Portal"></span></header>
<nav style="width:2470px;">
<ul>
<li><p>Home</p></li>
<li><p>About iTrade</p></li>
<li><p>Browse Auctions</p></li>
<li><p>F.A.Q's</p></li>
<li><p>Support</p></li>
<?php if($_SESSION['authorisation'] != 'knownuser'){
echo("<li class=\"spacer\"><p class=\"loginlogoutregister\">User Log In</p></li><li><p class=\"loginlogoutregister\">User Register</p></li>");
}
else{
echo("<li class=\"spacer\"><p class=\"loginlogoutregister\">User Logout</p></li>");
$loggedin = "<p>You are logged in.</p>";
}
if($_SESSION['authorisation'] != 'known_admin_user'){
echo("<li><p class=\"loginlogoutregister\">Admin</p></li>");
}
else{
echo("<li><p class=\"loginlogoutregister\">Admin</p></li><li><p class=\"loginlogoutregister\">Admin Logout</p></li>");
}
?>
</ul>
</nav>
<article style="width:2550px; height:100%;">
<h1>Admin - iTrade Users Details</h1>
<p>« Back to main admin page</p>
<ul>
<li>Users on iTrade</li>
<li>Admin Users on iTrade</li>
<li>Register a New Admin User</li>
</ul>
<p>Here is a table containing details about the currently registered users on iTrade:</p>
<fieldset style="width:2480px; height:100%; margin:0 auto;">
<legend style="font-size:30px; color:#000000; background-color:inherit;">A record of users on iTrade</legend>
<table>
<tr class="header_tables">
<th><u>User I.D</u></th>
<th><u>User Level</u></th>
<th><u>User-name</u></th>
<th><u>First Name</u></th>
<th><u>Last Name</u></th>
<th><u>Email</u></th>
<th><u>Password</u></th>
<th><u>Gender</u></th>
<th><u>Birthday</u></th>
<th><u>Landline Number</u></th>
<th><u>Mobile Number</u></th>
<th><u>Street Address</u></th>
<th><u>Suburb</u></th>
<th><u>City/Town</u></th>
<th><u>Province</u></th>
<th><u>Postcode</u></th>
<th><u>Closest Town</u></th>
<th><u>Confirmed?</u></th>
<th><u>Date Registered</u></th>
</tr>
<?php
$query = "SELECT * FROM user_list;";
$result = mysql_query($query, $connection) or die(mysql_error());
$users_on_itrade = " ";
while($row = mysql_fetch_array($result)){
echo("<tr>");
echo('<td>' . $row['user_id'] . '</td>');
echo('<td>' . $row['user_level'] . '</td>');
echo('<td>' . $row['user_username'] . '</td>');
echo('<td>' . $row['firstname'] . '</td>');
echo('<td>' . $row['lastname'] . '</td>');
echo('<td>' . $row['user_email'] . '</td>');
echo('<td>' . $row['user_pass'] . '</td>');
echo('<td>' . $row['gender']. '</td>');
echo('<td>' . $row['birthdate_day'] . $row['birthdate_month'] . $row['birthdate_year'] . '</td>');
echo('<td>' . $row['phoneNumber'] . '</td>');
echo('<td>' . $row['mobileNumber'] . '</td>');
echo('<td>' . $row['addressline1'] . '</td>');
echo('<td>' . $row['addressline2'] . '</td>');
echo('<td>' . $row['addressline3'] . '</td>');
echo('<td>' . $row['stateprovince'] . '</td>');
echo('<td>' . $row['postcode'] . '</td>');
echo('<td>' . $row['closest_town'] . '</td>');
echo('<td>' . $row['confirmed'] . '</td>');
echo('<td>' . $row['user_date'] . '</td>');
echo('<td>Edit</td>');
echo('<td>Delete</td>');
echo("<tr>");
}
?>
</table>
</fieldset>
</article>
<footer style="width:2550px;"><p>© Copyright 2011 iTrade LTD. Website design and development by InterKiwi Web Developers. Special thanks to the Computer Science department at the University of Otago, and the lecturers and lab administrators/demonstrators of the universities' Advanced Web Development paper.</p></footer>
</body>
</html>
This code is for the "edit" page link in "<td>Edit</td>":
<?php
require('admin_sessions.php');
require("../includes/dbconnect.php");
require('../includes/itradeuser.php');
?>
<?php
/*
This php script allows the administrator to edit a specific itrade user in the database.
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error)
{
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $user_id; ?>"/>
<fieldset class="userdetails">
<legend>User Credentials</legend>
<p><strong>ID:</strong> <?php echo $user_id; ?></p>
<ul>
<li><label for="user_email">Email Address:</label><input name="user_email" maxlength="50" id="user_email" size="40" type="text" value="<?php echo $user_email; ?>"><br></li>
<li><label for="user_pass">Your Password:</label><input name="user_pass" maxlength="50" id="user_pass" size="30" type="password" value="<?php echo $user_pass; ?>"><br></li>
<li><label for="user_pass_confirm">Password Again:</label><input name="user_pass_confirm" maxlength="50" id="user_pass_confirm" size="30" type="password" value="<?php echo $user_pass_confirm; ?>"><br></li>
<li><label for="user_username">Your Username:</label><input name="user_username" maxlength="50" id="user_username" size="30" type="text" value="<?php echo $user_username; ?>"></li>
</ul>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<ul>
<li><label for="firstname">First Name:</label><input name="firstname" type="text" id="firstname" size="25" maxlength="200" value="<?php echo $firstname; ?>" /><br></li>
<li><label for="lastname">Last Name:</label><input name="lastname" type="text" id="lastname" size="25" maxlength="200" value="<?php echo $lastname; ?>" /><br></li>
<li><label for="gender">Gender:</label>
<select name="gender" id="gender">
<option selected="" value=""> </option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="unspecified">Unspecified</option>
</select><br></li>
<li><label for"birthdate_day">Date of birth:</label>
<select name="birthdate_day" id="birthdate_day">
<option selected="selected" value=""></option>
<option value="1st">1</option>
<option value="2nd">2</option>
<option value="3rd">3</option>
<option value="4th">4</option>
<option value="5th">5</option>
<option value="6th">6</option>
<option value="7th">7</option>
<option value="8th">8</option>
<option value="9th">9</option>
<option value="10th">10</option>
<option value="11th">11</option>
<option value="12th">12</option>
<option value="13th">13</option>
<option value="14th">14</option>
<option value="15th">15</option>
<option value="16th">16</option>
<option value="17th">17</option>
<option value="18th">18</option>
<option value="19th">19</option>
<option value="20th">20</option>
<option value="21st">21</option>
<option value="22nd">22</option>
<option value="23rd">23</option>
<option value="24th">24</option>
<option value="25th">25</option>
<option value="26th">26</option>
<option value="27th">27</option>
<option value="28th">28</option>
<option value="29th">29</option>
<option value="30th">30</option>
<option value="31st">31</option>
</select>
<select name="birthdate_month" id="birthdate_month">
<option selected="selected" value=""></option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select><br></li>
<li><label for="birthdate_year">Birth Year:</label><input name="birthdate_year" type="number" maxlength="4" id="birthdate_year" size="4" value="<?php echo $birthdate_year; ?>"><br>
</li>
<li>
<label for="phoneNumber">Home Phone:</label>
<input name="phoneNumber" type="number" maxlength="9" id="phoneNumber" size="9" value="<?php echo $phoneNumber; ?>"><br></li>
<li><label for="mobileNumber">Mobile Number:</label>
<input name="mobileNumber" type="number" maxlength="11" id="mobileNumber" size="11" value="<?php echo $mobileNumber; ?>"><span class="informational">e.g: 0276123456</span><br></li>
<li><label for="addressline1">Street Address:</label>
<input name="addressline1" maxlength="100" id="addressline1" size="40" type="text" value="<?php echo $addressline1; ?>"><br></li>
<li><label for="addressline2">Suburb:</label>
<input name="addressline2" maxlength="100" id="addressline2" size="40" type="text" value="<?php echo $addressline2; ?>"><br></li>
<li><label for="addressline3">City:</label>
<input name="addressline3" maxlength="100" id="addressline3" size="40" type="text" value="<?php echo $addressline3; ?>"><br></li>
<li><label for="stateprovince">State/Province:</label>
<select name="stateprovince" id="stateprovince">
<option selected="selected" value="<?php echo $stateprovince; ?>"></option>
<option value="northland">Northland</option>
<option value="auckland">Auckland</option>
<option value="waikato">Waikato</option>
<option value="bayofplenty">Bay of Plenty</option>
<option value="eastcoast">East Coast</option>
<option value="hawkesbay">Hawkes Bay</option>
<option value="taranaki">Taranaki</option>
<option value="kingcountry">King Country</option>
<option value="wanganui">Wanganui</option>
<option value="manawatu">Manawatu</option>
<option value="wairarapa">Wairarapa</option>
<option value="wellington">Wellington</option>
<option value="nelsonbays">Nelson Bays</option>
<option value="marlborough">Marlborough</option>
<option value="buller">Buller</option>
<option value="westland">Westland</option>
<option value="northcanterbury">North Canterbury</option>
<option value="canterbury">Canterbury</option>
<option value="midcanterbury">Mid Canterbury</option>
<option value="southcanterbury">South Canterbury</option>
<option value="northotago">North Otago</option>
<option value="otago">Otago</option>
<option value="southland">Southland</option>
<option value="chathamisl">Chatham Islands</option>
</select><br></li>
<li><label for="postcode">Post Code:</label>
<input name="postcode" type="number" maxlength="4" id="postcode" size="4" value="<?php echo $postcode; ?>"><span class="informational">Find your post code</span><br></li>
<li><label for="closest_town">Closest Town:</label>
<select name="closest_town" id="closest_town">
<option selected="selected" value=""></option>
<option value="dargaville">Northland - Dargaville</option>
<option value="kaikohe">Northland - Kaikohe</option>
<option value="kaitaia">Northland - Kaitaia</option>
<option value="kawakawa">Northland - Kawakawa</option>
<option value="kerikeri">Northland - Kerikeri</option>
<option value="maungaturoto">Northland - Maungaturoto</option>
<option value="paihia">Northland - Paihia</option>
<option value="whangarei">Northland - Whangarei</option>
<option value="0"> </option>
<option value="aucklandcity">Auckland - Auckland City</option>
<option value="franklin">Auckland - Franklin</option>
<option value="greatbarrierisland">Auckland - Great Barrier Island</option>
<option value="helensville">Auckland - Helensville</option>
<option value="hibiscuscoast">Auckland - Hibiscus Coast</option>
<option value="manukaucity">Auckland - Manukau City</option>
<option value="northshore">Auckland - North Shore</option>
<option value="papakuracity">Auckland - Papakura City</option>
<option value="waihekeisl">Auckland - Waiheke Island</option>
<option value="waitakerecity">Auckland - Waitakere City</option>
<option value="warkworth">Auckland - Warkworth</option>
<option value="wellsford">Auckland - Wellsford</option>
<option value="0"> </option>
<option value="cambridge">Waikato - Cambridge</option>
<option value="coromandel">Waikato - Coromandel</option>
<option value="hamilton">Waikato - Hamilton</option>
<option value="huntly">Waikato - Huntly</option>
<option value="matamata">Waikato - Matamata</option>
<option value="morrinsville">Waikato - Morrinsville</option>
<option value="otorohanga">Waikato - Otorohanga</option>
<option value="paeroa">Waikato - Paeroa</option>
<option value="raglan">Waikato - Raglan</option>
<option value="taumarunui">Waikato - Taumarunui</option>
<option value="teawamutu">Waikato - Te Awamutu</option>
<option value="tekuiti">Waikato - Te Kuiti</option>
<option value="thames">Waikato - Thames</option>
<option value="tokoroa_putaruru">Waikato - Tokoroa/Putaruru</option>
<option value="waihi">Waikato - Waihi</option>
<option value="waihi_beach">Waikato - Waihi Beach</option>
<option value="whangamata">Waikato - Whangamata</option>
<option value="0"> </option>
<option value="katikati">Bay of Plenty - Katikati</option>
<option value="mt_maunganui">Bay of Plenty - Mt. Maunganui</option>
<option value="opotiki">Bay of Plenty - Opotiki</option>
<option value="rotorua">Bay of Plenty - Rotorua</option>
<option value="taupo">Bay of Plenty - Taupo</option>
<option value="tauranga">Bay of Plenty - Tauranga</option>
<option value="te_puke">Bay of Plenty - Te Puke</option>
<option value="turangi">Bay of Plenty - Turangi</option>
<option value="whakatane">Bay of Plenty - Whakatane</option>
<option value="0"> </option>
<option value="gisborne">Gisborne - Gisborne</option>
<option value="ruatoria">Gisborne - Ruatoria</option>
<option value="0"> </option>
<option value="dannevirke">Hawkes Bay - Dannevirke</option>
<option value="hastings">Hawkes Bay - Hastings</option>
<option value="napier">Hawkes Bay - Napier</option>
<option value="waipukurau">Hawkes Bay - Waipukurau</option>
<option value="wairoa">Hawkes Bay - Wairoa</option>
<option value="0"> </option>
<option value="hawera">Taranaki - Hawera</option>
<option value="mokau">Taranaki - Mokau</option>
<option value="new_plymouth">Taranaki - New Plymouth</option>
<option value="opunake">Taranaki - Opunake</option>
<option value="stratford">Taranaki - Stratford</option>
<option value="0"> </option>
<option value="ohakune">Wanganui - Ohakune</option>
<option value="taihape">Wanganui - Taihape</option>
<option value="waiouru">Wanganui - Waiouru</option>
<option value="wanganui">Wanganui - Wanganui</option>
<option value="0"> </option>
<option value="bulls">Manawatu - Bulls</option>
<option value="fielding">Manawatu - Feilding</option>
<option value="levin">Manawatu - Levin</option>
<option value="manawatu">Manawatu - Manawatu</option>
<option value="marton">Manawatu - Marton</option>
<option value="palmerston_north">Manawatu - Palmerston North</option>
<option value="0"> </option>
<option value="carterton">Wairarapa - Carterton</option>
<option value="featherston">Wairarapa - Featherston</option>
<option value="greytown">Wairarapa - Greytown</option>
<option value="martinborough">Wairarapa - Martinborough</option>
<option value="masterton">Wairarapa - Masterton</option>
<option value="paihiatua">Wairarapa - Pahiatua</option>
<option value="woodville">Wairarapa - Woodville</option>
<option value="0"> </option>
<option value="kapiti">Wellington - Kapiti</option>
<option value="lower_hutt">Wellington - Lower Hutt City</option>
<option value="porirua">Wellington - Porirua</option>
<option value="upper_hutt">Wellington - Upper Hutt City</option>
<option value="wellington">Wellington - Wellington City</option>
<option value="0"> </option>
<option value="golden_bay">Nelson Bays - Golden Bay</option>
<option value="motueka">Nelson Bays - Motueka</option>
<option value="murchison">Nelson Bays - Murchison</option>
<option value="nelson">Nelson Bays - Nelson</option>
<option value="picton">Nelson Bays - Picton</option>
<option value="0"> </option>
<option value="blenheim">Marlborough - Blenheim</option>
<option value="marlborough_sounds">Marlborough - Marlborough Sounds</option>
<option value="0"> </option>
<option value="greymouth">West Coast - Greymouth</option>
<option value="hokitika">West Coast - Hokitika</option>
<option value="westport">West Coast - Westport</option>
<option value="0"> </option>
<option value="akaroa">Canterbury - Akaroa</option>
<option value="amberley">Canterbury - Amberley</option>
<option value="ashburton">Canterbury - Ashburton</option>
<option value="cheviot">Canterbury - Cheviot</option>
<option value="christchurch">Canterbury - Christchurch City</option>
<option value="darfield">Canterbury - Darfield</option>
<option value="fairlie">Canterbury - Fairlie</option>
<option value="geraldine">Canterbury - Geraldine</option>
<option value="hamnersprings">Canterbury - Hanmer Springs</option>
<option value="kaiapoi">Canterbury - Kaiapoi</option>
<option value="kaikoura">Canterbury - Kaikoura</option>
<option value="mtcook">Canterbury - Mt Cook</option>
<option value="rangiora">Canterbury - Rangiora</option>
<option value="0"> </option>
<option value="timaru_oamaru_kurow">Timaru - Oamaru - Kurow</option>
<option value="timaru_oamaru_oamaru">Timaru - Oamaru - Oamaru</option>
<option value="timaru_oamaru_timaru">Timaru - Oamaru - Timaru</option>
<option value="timaru_oamaru_twizel">Timaru - Oamaru - Twizel</option>
<option value="timaru_oamaru_waimate">Timaru - Oamaru - Waimate</option>
<option value="0"> </option>
<option value="alexandra">Otago - Alexandra</option>
<option value="balclutha">Otago - Balclutha</option>
<option value="cromwell">Otago - Cromwell</option>
<option value="dunedin">Otago - Dunedin</option>
<option value="lawrence">Otago - Lawrence</option>
<option value="milton">Otago - Milton</option>
<option value="palmerston">Otago - Palmerston</option>
<option value="queenstown">Otago - Queenstown</option>
<option value="ranfurly">Otago - Ranfurly</option>
<option value="roxburgh">Otago - Roxburgh</option>
<option value="wanaka">Otago - Wanaka</option>
<option value="0"> </option>
<option value="bluff">Southland - Bluff</option>
<option value="edendale">Southland - Edendale</option>
<option value="gore">Southland - Gore</option>
<option value="invercargill">Southland - Invercargill</option>
<option value="lumsden">Southland - Lumsden</option>
<option value="otautau">Southland - Otautau</option>
<option value="riverton">Southland - Riverton</option>
<option value="stewart_island">Southland - Stewart Island</option>
<option value="te_anau">Southland - Te Anau</option>
<option value="tokanui">Southland - Tokanui</option>
<option value="winton">Southland - Winton</option>
<option value="0"> </option>
<option value="chathamisl">Chatham Islands</option>
</select><br></li>
</ul>
</fieldset>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit'])){
if (is_numeric($_POST['user_id'])){
// get form data, making sure it is valid
$user_id = $_POST['user_id'];
$user_email = mysql_real_escape_string($_POST['user_email']);
$user_pass = mysql_real_escape_string($_POST['user_pass']);
$user_pass_confirm = mysql_real_escape_string($_POST['user_pass_confirm']);
$user_username = mysql_real_escape_string($_POST['user_username']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$gender = mysql_real_escape_string($_POST['gender']);//optional field
$birthdate_day = mysql_real_escape_string($_POST['birthdate_day']);
$birthdate_month = mysql_real_escape_string($_POST['birthdate_month']);
$birthdate_year = mysql_real_escape_string($_POST['birthdate_year']);
$phoneNumber = mysql_real_escape_string($_POST['phoneNumber']);
$mobileNumber = mysql_real_escape_string($_POST['mobileNumber']);
$addressline1 = mysql_real_escape_string($_POST['addressline1']);
$addressline2 = mysql_real_escape_string($_POST['addressline2']); // optional field
$addressline3 = mysql_real_escape_string($_POST['addressline3']);
$stateprovince = mysql_real_escape_string($_POST['stateprovince']);
$postcode = mysql_real_escape_string($_POST['postcode']); // optional field
$closest_town = mysql_real_escape_string($_POST['closest_town']); //optional field
$date = time();
// check that firstname/lastname fields are both filled in
if ($firstname == '' || $lastname == '' || $user_email =='' || $user_pass == '' || $user_pass_confirm == '' || $user_username == '' || $firstname =='' || $lastname == '' || $gender == '' || $birthdate_day == '' || $birthdate_month == '' || $birthdate_year == '' || $phoneNumber == '' || $mobileNumber == '' || $addressline1 == '' || $addressline2 == '' || $addressline3 == '' || $stateprovince == '' || $postcode == '' || $closest_town == ''){
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error);
}
else{
// save the data to the database
mysql_query("UPDATE user_list SET user_email='$user_email', user_pass=sha1('$user_pass.$salt'), user_pass_confirm=sha1('$user_pass_confirm.$salt'), user_username='$user_username', firstname='$firstname', lastname='$lastname', gender='$gender', birthdate_day='$birthdate_day, birthdate_month='$birthdate_month', birthdate_year='$birthdate_year', phoneNumber='$phoneNumber', mobileNumber='$mobileNumber', addressline1='$addressline1', addressline2='$addressline2', addressline3='$addressline3', stateprovince='$stateprovince', postcode='$postcode', closest_town='$closest_town' WHERE user_id='$user_id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: itradeusers.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error! ID not valid.';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] > 0)
{
// query db
$user_id = $_GET['user_id'];
$result = mysql_query("SELECT * FROM user_list WHERE user_id=$user_id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$user_id = $row['user_id'];
$user_email = $row['user_email'];
$user_pass = $row['user_pass'];
$user_pass_confirm = $row['user_pass_confirm'];
$user_username = $row['user_username'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$gender = $row['gender'];
$birthdate_day = $row['birthdate_day'];
$birthdate_month = $row['birthdate_month'];
$birthdate_year = $row['birthdate_year'];
$phoneNumber = $row['phoneNumber'];
$mobileNumber = $row['mobileNumber'];
$addressline1 = $row['addressline1'];
$addressline2 = $row['addressline2'];
$addressline3 = $row['addressline3'];
$stateprovince = $row['stateprovince'];
$postcode = $row['postcode'];
$closest_town = $row['closest_town'];
// show form
renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error);
}else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error! the \'id\' is not valid.';
}
}
?>
If someone could tell me what I have done wrong, or even explain to me a better way of doing something like this, please let me know... Thanks in advance!
First of all, it looks like you're storing passwords in plain text. That is a big no no!
For updating user info have a look at the UPDATE command for mysql: http://dev.mysql.com/doc/refman/5.0/en/update.html
For the delete/block issue, you could add another column that stores the user status (deleted, blocked, active, etc). You could then check the status of this column when the user logs in or visits a page.