Ok, so I made a registering script for my page. It enters data fine. No I want to add radio buttons, and depending on what radio button is selected, I want certain fields in the ‘users’ table in my mysql database to be changed.
I have got what I would think could work, but sadly, it doesn’t do the editing I want. The default values for each field is ‘1’, however if lets say radio button 1 is selected, I want field 3 to change to 5. (Out of lets say in this case, 7 fields, all named field1, field2, field3, etc) on top of that then I have the username being added to the database, and email, and password (in md5) I have the password, email, and username being added, and then all the fields are added fine as ‘1’ but they don’t change to the 5 or whatever I want. Any idea on what I could be doing wrong?
[CODE]<?
// process.php
$mode = $_POST['mode']; // Make sure a mode is specified.
if ($mode == "") {
print("No mode specified. Please contact the webmaster to have this problem fixed.");
die();
}
require("vars.php"); // Get mysql info.
mysql_connect($host, $user, $pass) or die("MySQL connection error.");
mysql_select_db($db) or die("No such database."); // Connect to the right database
switch ($mode) {
case "register";
// First, check to make sure that all the data is filled in.
$username = $_POST['username']; // Min 4, Max 16
$password = $_POST['password']; // Min 4, Max 10
$cpassword = $_POST['cpassword']; // Min 4, Max 10
$email = $_POST['email']; // Min 4, Max 40
if ($username == "") {
header("Location: register.php?error=1&email=$email");
die();
}
if ($password == "") {
header("Location: register.php?error=2&email=$email&username=$username");
die();
}
if ($cpassword == "") {
header("Location: register.php?error=3&email=$email&username=$username");
die();
}
if ($email == "") {
header("Location: register.php?error=4&username=$username");
die();
}
// Check to see if the passwords match
if ($password != $cpassword) {
header("Location: register.php?error=5&username=$username&email=$email");
die();
}
// Now check the minimum lengths
// Check the maximum lengths
if (strlen($username) > 15) {
header("Location: register.php?error=9&username=$username&email=$email");
die();
}
if (strlen($password) > 50) {
header("Location: register.php?error=10&username=$username&email=$email");
die();
}
if (strlen($email) > 40) {
header("Location: register.php?error=11&username=$username&email=$email");
die();
}
// Now check to make sure that we don't have the same username.
$temp = strtolower($username);
$query = mysql_query("SELECT COUNT(LOWER(username)) FROM users WHERE username='$temp'");
$result = mysql_fetch_array($query, MYSQL_NUM);
if ($result[0] != 0) {
die();
}
// Check for duplicate email addresses.
$temp = strtolower($email);
$query = mysql_query("SELECT COUNT(LOWER(email)) FROM users where email='$email'");
$result = mysql_fetch_array($query, MYSQL_NUM);
if ($result[0] != 0) {
die();
}
// We have completed all the checks.
// MD5 the password.
$password = md5($password);
// Insert the data into the user page.
mysql_query("INSERT INTO users (username, password, email) VALUES ('$username','$password','$email)");
mysql_query("INSERT INTO other (current,possible) VALUES ($current,$energypossible)");
mysql_query("INSERT INTO item2 (current,bank23) VALUES ('$current2','$bank23')");
// Redirect to login page
}
if ( isSet($_POST['submit']) )
{
echo '<pre>';
print_r($_POST);
echo '</pre>';
{
switch( strToLower($_POST['class']) )
{
case "1":
$result = mysql_query("UPDATE users SET field1='10,field3='12' where id=$id");
break;
case "2":
$result = mysql_query("UPDATE users SET field1='3,field3='10'where id=$id");
break;
case "3":
$result = mysql_query("UPDATE users SET field1='6,field3='14' where id=$id");
break;
case "4":
$result = mysql_query("UPDATE users SET field1='2,field3='8' where id=$id");
break;
case "5":
$result = mysql_query("UPDATE users SET field1='9,field3='12' where id=$id");
break;
case "6":
$result = mysql_query("UPDATE users SET field1='5,field3='10' where id=$id");
}
}
switch ($mode) {
case "login":
// Get user data
$username = $_POST['username'];
$password = $_POST['password'];
if ($username == "") {
header("Location: main.php?error=1");
die();
}
if ($password == "") {
header("Location: main.php?error=2");
die();
}
// MD5 the password. Lower the username
$password = md5($password);
$username1 = strtolower($username);
$query = mysql_query("SELECT COUNT(LOWER(username)), id FROM users where username='$username' GROUP BY username");
$result = mysql_fetch_array($query, MYSQL_NUM);
if ($result[0] != 1) {
header("Location: main.php?error=3");
die();
}
$query = mysql_query("select password from users where id=$result[1]");
$id1 = $result[1];
$result = mysql_fetch_array($query, MYSQL_NUM);
if ($result[0] == $password) {
session_start();
$_SESSION['id'] = $id1;
// Get the actual user name
$query = mysql_query("SELECT username FROM users where id=$id1");
$result = mysql_fetch_array($query, MYSQL_NUM);
$username = $result[0];
$_SESSION['username'] = $username;
$_SESSION['password'] = $password;
// Check to see if they want to be logged in for a week.
$week = $_POST['week'];
if ($week == "yes") {
// add the cookie data
// find out the time a week from now
$time = time();
$time1 = 7 * 24;
$time1 = $time1 * 60 *60;
$time = $time + $time1;
setcookie("username", $username, $time,"/");
setcookie("password", $password, $time,"/");
setcookie("id", $id1,$time,"/");
setcookie("signedin","true",$time,"/");
}
header("Location: home.php");
die();
} else {
header("Location: main.php?error=3");
}
}
[/CODE]
<html>
<head>
<title>Register</title>
</head>
<body>
<?
require("function.php");
$error = mysqlconnect();
if ($error === FALSE) {
die("Error connecting to MySQL.");
}
if (isset($_GET['error'])) {
print("<b><font color=Red>");
switch ($_GET['error']) {
case 1:
print("You forgot to enter your username.");
break;
case 2:
print("You forgot to enter your password.");
break;
case 3:
print("You forgot to confirm your password.");
break;
case 4:
print("You forgot to enter your e-mail.");
break;
case 5:
print("Your passwords do not match.");
break;
case 6:
print("Your password must be greater than 4 characters long.");
break;
case 7:
print("Your username must be greater than 4 characters long.");
break;
case 8:
print("Your e-mail must be greater than 4 characters long.");
break;
case 9:
print("Your username may not be more than 15 characters long.");
break;
case 10:
print("Your password may not be more than 50 characters long.");
break;
case 11:
print("Your e-mail cannot be longer than 40 characters.");
break;
case 12:
print("The username, $username, is already in use.");
break;
case 13:
print("The email, $email, is already in use.");
break;
default:
print("Error information not understood. Please contact the webmaster.");
break;
}
print("</font><br><hr>");
}
?>
<form action='process.php' method='post'>
<input type='hidden' name='mode' value='register'>
Username: <input type='text' name='username' size=16 maxlength=15 value='<? print $_GET['username']; ?>'><br>
Password: <input type='password' name='password' size=10 maxlength=50><br>
Confirm Password: <input type='password' name='cpassword' size=10 maxlength=50><br>
E-mail: <input type='text' name='email' size=40 maxlength=40 value='<? print $_GET['email']; ?>'><br>
<input type="radio" name="class" value="A" selected="selected" /> A
<br />
<input type="radio" name="class" value="B" /> B
<br />
<input tupe="submit" name="submit" /><!-- Blahhhh-->
</form>
[code=php]<?
echo '<pre>';
print_r($_POST);
echo '</pre>';
[/code]
[code=php]Array
(
[mode] => register
[username] => testun
[password] => testpw
[cpassword] => testpwc
[email] => testemail
[class] => A
[submit] => Submit Query
)[/code]
0.1.9 — BETA 5.27