Why doesn't that SQL code work? What error are you getting? It could be that the table `users` already exists and that's the error that you're getting. In that case, you need to drop `users` first and then create your new table.
Try this:
Code:
DROP TABLE `users`;
CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
username VARCHAR(30),
password VARCHAR(30),
firstname VARCHAR(30),
lastname VARCHAR(30),
age VARCHAR(30),
gender VARCHAR(30),
email VARCHAR(30),
actor VARCHAR(30))
I made a couple of mistakes with the code I gave you before (I guess I was kind of tired yesterday) and that's why the backstage worker menu wasn't working. Sorry about that.
I forgot to set the onclick attributes and I also did not write the script properly.
Your code has a lot of HTML errors too. You have multiple <body> and <head> tags, some of which execute after the body is completed. Also, you changed the field name of "actor" to "shade". I modified the PHP to reflect that change.
Here is the revised code:
PHP Code:
<html>
<head>
<body style="background-color:lightgreen">
<?php
mysql_connect("localhost", "****", "***") or die(mysql_error());
mysql_select_db("****") or die(mysql_error());
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('You did not complete all of the required fields');
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the username '.$_POST['username'].' is already in use.');
}
// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Your passwords did not match. ');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}
if($_POST[firstname] != '' && $_POST[firstname] != '' && $_POST[firstname] != '' && $_POST[firstname] != '') {
// now we insert it into the database
//Check if typeSelector is set.
if($_POST['typeSelector'] != '') {
$type = $_POST['typeSelector'];
} else {
$type = $_POST[shade];
}
$insert = "INSERT INTO users (username, password, firstname, lastname, age, gender, email, actor)
VALUES ('".$_POST['username']."', '".$_POST['pass']."', '$_POST[firstname]', '$_POST[lastname]', '$_POST[age]', '$_POST[gender]', '$_POST[email]', '$type')";
$add_member = mysql_query($insert);
echo <<<EOF
<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>
EOF;
} else {
echo "Please fill in all of the required fields.";
}
}
else
{
?>
<?php include("links.php"); ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table border="0">
<tr><td colspan="2"><h1>Register</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="60">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="10">
</td></tr>
<tr><td>First name:</td><td>
<input name="lastname" type="text" maxlength="10">
</td></tr>
<tr><td>Last name:</td><td>
<input name="firstname" type="text" maxlength="10">
</td></tr>
<tr><td>Age:</td><td>
<select name="age">
<?php $i = 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"; $i++; } ?>
</select>
</td></tr>
<tr><td>Email:</td><td>
<input name="email" type="text" maxlength="10">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><td>Actor/Director?:</td><td>
<input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor
<input type="radio" name="shade" value="Backstageworker" id="backstage" onclick="chgType()">Backstage worker <br />
<select name="typeSelector" id="typeSelector" style="visibility: hidden">
<option>Set mover</option>
<option>Sound</option>
</select>
</td></tr>
<tr><th colspan="2"><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>
<script type="text/javascript">
function chgType() {
var actor = document.getElementById('actor');
var backstage = document.getElementById('backstage');
if(backstage.checked === true) {
document.getElementById('typeSelector').style.visibility = 'visible';
} else {
document.getElementById('typeSelector').style.visibility = 'hidden';
}
}
</script>
<?php
}
?>
</body>
</html>
Bookmarks