View Full Version : Php login/registration error
keyboard
07-26-2011, 11:19 PM
Hi everyone,
On my site it's coming up with this error
Parse error: syntax error, unexpected $end in /home1/keyboard/public_html/Canberra Amatuer Productions/databaseedit.php on line 101
I've commented it out so I know that the error is somewhere in here
<?php
mysql_connect("localhost", "****", "****") or die(mysql_error());
mysql_select_db("****") or die(mysql_error());
if (isset($_POST['submit'])) {
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] | !$_POST['age'] ) {
die('You did not complete all of the required fields');
}
Any help would be appreciated
djr33
07-26-2011, 11:41 PM
Unexpected $end means that your code does not have matching {} pairs. (Or something similar).
In this case it looks like your middle if statement is not ended. Add } to the end and it should be fine. Unless you already have that ended somewhere else.
also, | is probably not the operator you're intending to use. It may be working for your specific case at the moment, but it won't be reliable.
| is the bitwise "OR" operator. It compares the state of the bits (i.e., the 1's and 0's) in the binary values (not the string/boolean/integer/etc. values) and returns the bit values that all of the given values include. Here's a good introductory tutorial (http://www.litfuel.net/tutorials/bitwise.htm) on the subject.
for comparing values the way it appears you intend to, you need to be using || - the logical "OR" operator. it compares the evaluated result of each term (i.e., "true" or "false").
also also, ! $somevar is not the best way to do it. If $somevar is not set, then this will still evaluate the way you expect, but it will also throw a warning. I generally use empty($somevar) , which does the same evaluation but also checks if the variable is set or not (empty($somevar) is like !isset($somevar) || $somevar == FALSE).
keyboard
07-27-2011, 04:18 AM
The idea is that the form submits to the page the form is on (self) and once it has been submited it will then run the checks to see if the fields are empty etc.
Is this what the script should look like
if (isset($_POST['submit'])) {
if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['age'] ) }
{
die('You did not complete all of the required fields');
}
bluewalrus
07-27-2011, 04:53 AM
No, you're closing the first conditional with the second conditional in it.
if (isset($_POST['submit'])) {
if (!$_POST['username'] || !$_POST['pass'] || !$_POST['pass2'] || !$_POST['age'] ){
die('You did not complete all of the required fields');
}
//Whatever else is done when the form is submitted
} else {
//what ever is done when the form isnt submitted
// remove from 'else {' if you dont want to distinguish
Also as Traq says, it's better to use the empty so you don't fill your error log with warnings.
empty($somevar);
Traq, do you know why it throws the warning, you are stilling using the value in the empty, so it is still undefined. For example I've had to use this
if (!empty($_SERVER['HTTP_REFERER']))
$refer = $_SERVER['HTTP_REFERER'];
else
$refer = '';
<input type="hidden" name="refer" value="<?php echo $refer; ?>" />
Instead of just
<input type="hidden" name="refer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
Seems like extra work, outputting nothing there won't/doesn't break anything. Thanks.
keyboard
07-27-2011, 05:06 AM
<?php
// Connects to your Database
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']);
}
// now we insert it into the database
$insert = "INSERT INTO users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$add_member = mysql_query($insert);
?>
<h1>Registered</h1>
<p>Thank you, you have registered - you may now login</a>.</p>
<?php
}
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>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="10">
</td></tr>
<tr><th colspan=2><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>
<?php
}
?>
<html>
<head>
<body style="background-color:lightgreen">
</head>
<body>
</body>
</html>
This is the origanal code and it works fine. I'm trying to add in more fields like age, gender, email, actor/director, first name, Last name. I would like to have age and actor/director as radio inputs.
How do I include all this into the script and also how are radio inputs stored in an sql database
Traq, do you know why it throws the warning, you are stilling using the value in the empty, so it is still undefined. For example I've had to use this
if (!empty($_SERVER['HTTP_REFERER']))
$refer = $_SERVER['HTTP_REFERER'];
else
$refer = '';
<input type="hidden" name="refer" value="<?php echo $refer; ?>" />
Instead of just
<input type="hidden" name="refer" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" />
yeah, I do similar stuff all the time. I typically use the ternary operator, though (I love that thing)
$val = empty($VAL) ? NULL: $VAL;
<sorry> </thread-hijack> </sorry>
keyboard
07-27-2011, 06:54 AM
<sorry> </thread-hijack> </sorry>
Thats ok
keyboard
07-29-2011, 08:02 AM
Anyone?
JShor
07-30-2011, 12:49 AM
Well, I don't know you would make the age radio buttons and have it fit practically, so I modified it so that it would populate a select combo box with ages 1 - 110 (I also modified it to have the fields: firstname, lastname, age, gender, email, actor)
<?php
// Connects to your Database
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
$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]', '$_POST[actor]')";
$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
{
?>
age, gender, email, actor/director, first name, Last name
<?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="password" name="actor" value="actor" maxlength="10"> Actor<br>
<input type="password" name="actor" value="director" maxlength="10"> Director
</td></tr>
<tr><th colspan="2"><input type="submit" name="submit" value="Register"></th></tr> </table>
</form>
<?php
}
?>
<html>
<head>
<body style="background-color:lightgreen">
</head>
<body>
</body>
</html>
Keep in mind that you would need to modify your MySQL database to include these extra fields:
firstname, lastname, age, gender, email, actor
keyboard
07-30-2011, 11:14 PM
Thank you so much. THis is absaloutly amazing. Just one last thing. Could you please show me how I can modify the actor and director into a radio button so they are either an actor or a backstage worker. then if they select backstage worker. it comes up with a thing (dropdown menu like AGE) which gives you options like setmover lighting sound etc.
JShor
07-30-2011, 11:37 PM
I'm not sure I understand. Do you mean that you want to replace the director value with backstage worker?
That's easy to do, just change the value of the radio button to "backstage worker".
As for having a drop-down menu appear, that could be done in JavaScript. Here's a small example that should work:
<script type="text/javascript">
function chgType(obj) {
if(obj.checked === true) {
document.getElementById('typeSelector').visibility = 'visible';
} else {
document.getElementById('typeSelector').visibility = 'hidden';
}
</script>
...insert that within your <HEAD> tags.
And modify your table row to include this. Just add more option tags with the innerHTML of whatever you want the other values to be.
<tr><td>Actor/Director?:</td><td>
<input type="password" name="actor" value="actor" maxlength="10" selected="selected"> Actor<br>
<input type="password" name="actor" value="backstage worker" maxlength="10"> Backstage worker.
<select name="typeSelector" id="typeSelector" style="visibility: hidden">
<option>Set mover</option>
<option>Sound</option>
</select>
</td></tr>
The select menu will be hidden when the option for backstage worker is not selected, and appear when it is.
Also, since we have a new field here, we'll need to modify the PHP code to check if the value of the field is set. If it is, we'll override the old _POST value of the 'actor' field.
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[actor];
}
$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.";
}
keyboard
07-31-2011, 12:05 AM
Hi thanks for all your help.
what I mean is instead of having actor and as password fields I would like to have them as radio buttons
Do you wish to work as an actor or as a backstage worker <br />
<input type="radio" name="shade" value="dark">Actor
<input type="radio" name="shade" value="light">Backstage worker <br />
</form>
Then if they select back stage worker. A drop down comes up and they can select what type of backstage work. such as set mover etc.
JShor
07-31-2011, 02:33 AM
The code that I posted before should do what you're trying to accomplish.
Unless I'm missing something, I understood that you want to have two radio buttons: actor and backstage worker.
When backstage worker is selected, a drop-down menu appears with the options of set mover, lights, etc.
Please be more specific as to what you're trying to do if this isn't the case.
keyboard
07-31-2011, 06:47 AM
"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'm trying to make a sql table. This dosen't work. Any help would be great
keyboard
07-31-2011, 06:59 AM
<?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[actor];
}
$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
{
?>
age, gender, email, actor/director, first name, Last name
<?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">Actor
<input type="radio" name="shade" value="Backstageworker">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>
<?php
}
?>
<html>
<head>
<body style="background-color:lightgreen">
<script type="text/javascript">
function chgType(obj) {
if(obj.checked === true) {
document.getElementById('typeSelector').visibility = 'visible';
} else {
document.getElementById('typeSelector').visibility = 'hidden';
}
</script>
</head>
<body>
</body>
</html>
Also, is this what the finale code should look like because I tried it and everything worked except the are you an actor/backstage if you are back stage a menu comes down with a list of backstage jobs. Thankyou so much for the help you've given
JShor
07-31-2011, 05:05 PM
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:
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:
<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>
keyboard
07-31-2011, 08:53 PM
Thankyou so much. The drop down box works. It's so awesome!
However, this error comes up every time I try to submit the form
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@randomhelp4you.heliohost.org and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
--------------------------------------------------------------------------------
Apache/2.2.16 (Unix) mod_ssl/2.2.16 OpenSSL/0.9.8e-fips-rhel5 mod_mono/2.6.3 FrontPage/5.0.2.2635 mod_bwlimited/1.4 mod_auth_passthrough/2.1 mod_wsgi/3.3 Python/2.7.1 Server at randomhelp4you.heliohost.org Port 80
Any help?
keyboard
07-31-2011, 09:06 PM
Actually now it's not coming up with the error but their is another problem.
making an account is working fine but when I try and login it says the information I entered is incorrect. I think it's a problem with the password.
The md5 for james is b4cc344d25a2efe540adbf2678e2304c
But on my database with that password it says b4cc344d25a2efe540adbf2678e230
b4cc344d25a2efe540adbf2678e2304c
b4cc344d25a2efe540adbf2678e230
would that cause a problem like that. If so how should I fix it.
JShor
07-31-2011, 09:12 PM
You set your database field "password" to VARCHAR(30) (meaning that it will only put in the first 30 characters of any entry.
Typically, people that use VARCHAR set it to 255 characters. md5-encrypted hashes are 32 characters.
Change your "password" field to accept more characters, and that should solve your problem.
keyboard
08-04-2011, 01:57 AM
When I am registering on the site it is inserting the firstname input into the lastname row in the sql database and the lastname input into the firstname row? Any help
bluewalrus
08-04-2011, 02:28 AM
Can you please post the HTML and PHP you are using currently?
JShor
08-04-2011, 03:59 AM
I caught it. You mixed up the two fields in your HTML originally. You had the "lastname" field where it was labeled "First name:" and the "firstname" field where it said "Last name:".
Here's the revised 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="firstname" type="text" maxlength="10">
</td></tr>
<tr><td>Last name:</td><td>
<input name="lastname" 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>
keyboard
08-04-2011, 07:56 AM
Thanks so much for everything JShor. You've been really helpfull.
keyboard
08-05-2011, 11:09 PM
On login.php
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("keyboard_test") or die(mysql_error());
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
if ($pass != $info['password'])
{
}
else
{
header("Location: member.php");
}
}
}
//if the login form is submitted
if (isset($_POST['submit'])) {
$george = $_POST['username'];
if ("$george == george")
{
die ('error');
}
// makes sure they filled it in
if(!$_POST['username'] | !$_POST['pass']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['email'] = addslashes($_POST['email']);
}
$check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=database.php>Click Here to Register</a>');
}
while($info = mysql_fetch_array( $check ))
{
$_POST['pass'] = stripslashes($_POST['pass']);
$info['password'] = stripslashes($info['password']);
$_POST['pass'] = md5($_POST['pass']);
//gives error if the password is wrong
if ($_POST['pass'] != $info['password']) {
die('I am sorry, the information entered was incorrect');
}
else
{
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie(ID_my_site, $_POST['username'], $hour);
setcookie(Key_my_site, $_POST['pass'], $hour);
//then redirect them to the members area
header("Location: member.php");
}
}
}
else
{
// if they are not logged in
?>
<?php include("links.php"); ?>
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
<table border="0">
<tr><td colspan=2><h1>Login</h1></td></tr>
<tr><td>Username:</td><td>
<input type="text" name="username" maxlength="40">
</td></tr>
<tr><td>Password:</td><td>
<input type="password" name="pass" maxlength="50">
</td></tr>
<tr><td colspan="2" align="right">
<input type="submit" name="submit" value="Login">
</td></tr>
</table>
</form>
<?php
}
?>
<html>
<head>
<body style="background-color:lightgreen">
</head>
<body>
</body>
</html>
I've added in this bit
$george = $_POST['username'];
if ("$george == george")
{
die ('HELLO GEORGE');
}
I want it to die if they enter george as the username but it is dying for everything. It dosen't matter what you put as the username it still dies? Any help?
("$george == george") will always evaluate to true.
($george == "george") is what you're trying to do.
keyboard
08-06-2011, 05:24 AM
Thanks Traq
keyboard
09-04-2011, 03:54 AM
Okay, I just noticed a problem.
<html>
<head>
<script>
var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}
function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}
</script>
<script language="javascript">
function disableField()
{
document.getElementById('checky').disabled = false;
}
</script>
</head>
<body>
<body style="background-color:lightgreen">
<?php
require "database.php";
//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'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['age'] | !$_POST['gender'] | !$_POST['email'] )
{
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']; ?>" name="agreeform" onSubmit="return defaultagree(this)" 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="20">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="20">
</td></tr>
<tr><td>First name:</td><td>
<input name="firstname" type="text" maxlength="15">
</td></tr>
<tr><td>Last name:</td><td>
<input name="lastname" type="text" maxlength="15">
</td></tr>
<tr><td>Age:</td><td>
<select name="age">
<?php $i = 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"; $i++; } ?>
</select>
<tr><td>Gender:</td><td>
<input type="radio" name="gender" value="Male" id="Male">Male
<input type="radio" name="gender" value="Female" id="Female">Female <br />
</td></tr>
<tr><td>Email:</td><td>
<input name="email" type="text" maxlength="30">
</td></tr>
<tr><td>Actor/Backstage?:</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>
<br /><br /><br />
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)" id="checky" disabled="true"><b>I agree to the <a href="terms.php" onclick="disableField()" target="_blank">terms and conditions</a></b><br>
</td></tr>
<tr><th colspan="2"><input type="submit" name="submit" value="Register" disabled></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>
Thats the current working code.
In this bit here
<tr><td>Actor/Backstage?:</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 />
If they select backstage worker - sound, it inserts Sound.
If they select backstage worker - set mover, it inserts set mover.
But if I select actor and no subcatagory(because their isn't one) it inserts backstage worker?
Any help?
JShor
09-04-2011, 11:28 AM
There's a function called chgType() in your HTML radio buttons, which is the event that is triggered. The code you provided does not have the function chgType() listed anywhere.
keyboard
09-04-2011, 11:25 PM
Um it's right after the submit button.
<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>
JShor
09-05-2011, 12:13 AM
Do you have a link to the page so I can see exactly what's wrong?
keyboard
09-05-2011, 12:20 AM
No problem actually shows up on the page. It's only the information that's being inserted into the database.
http://randomhelp4you.heliohost.org/Canberra%20Amatuer%20Productions/databaseedit.php
Thats the registration page that the form is on. I'm not actually using the information submitted yet so I can't really show you. If theirs anything I can do to help, please tell me.
JShor
09-05-2011, 01:41 AM
Have the script print the variable $type somewhere, and tell me what the value is when you submit it under the conditions that you described. The code looks like it should work just fine.
keyboard
09-05-2011, 01:46 AM
when I select setmover it prints setmover
when I select sound it prints sound
when I select actor it prints setmover
//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 $type;
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
{
?>
I added in this bit
echo $type;
JShor
09-05-2011, 01:59 AM
Try replacing this:
if($_POST['typeSelector'] != '') {
$type = $_POST['typeSelector'];
} else {
$type = $_POST[shade];
}
With this:
if($_POST[shade] == 'Backstageworker') {
$type = $_POST[typeSelector];
} else {
$type = $_POST[shade];
}
keyboard
09-05-2011, 03:09 AM
Yep, it works now. Thanks for all your help JShor!
keyboard
09-05-2011, 09:44 AM
Okay, one more thing.
<html>
<head>
<script>
var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}
function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}
</script>
<script language="javascript">
function disableField()
{
document.getElementById('checky').disabled = false;
}
</script>
</head>
<body>
<body style="background-color:lightgreen">
<?php
require "database.php";
//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'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['age'] | !$_POST['gender'] | !$_POST['email'] )
{
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[shade] == 'Backstageworker') {
$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 $type;
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']; ?>" name="agreeform" onSubmit="return defaultagree(this)" 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="20">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="20">
</td></tr>
<tr><td>First name:</td><td>
<input name="firstname" type="text" maxlength="15">
</td></tr>
<tr><td>Last name:</td><td>
<input name="lastname" type="text" maxlength="15">
</td></tr>
<tr><td>Age:</td><td>
<select name="age">
<?php $i = 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"; $i++; } ?>
</select>
<tr><td>Gender:</td><td>
<input type="radio" name="gender" value="Male" id="Male">Male
<input type="radio" name="gender" value="Female" id="Female">Female <br />
</td></tr>
<tr><td>Email:</td><td>
<input name="email" type="text" maxlength="30">
</td></tr>
<tr><td>Are you interested in backstage work or onstage?:</td><td>
<input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor
<input type="radio" name="shade" value="Backstage" id="backstage" onclick="chgType()">Backstage worker
<input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<br />
<select name="typeSelector" id="typeSelector" style="visibility: hidden">
<option>Set mover</option>
<option>Sound</option>
</select>
<br /><br /><br />
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)" id="checky" disabled="true"><b>I agree to the <a href="terms.php" onclick="disableField()" target="_blank">terms and conditions</a></b><br>
</td></tr>
<tr><th colspan="2"><input type="submit" name="submit" value="Register" disabled></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>
In the code I added in this bit
<input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<br />
So that they can select that they are interested in both. But then the original code dosen't work. When you select sound or set mover it just says $type prints Backstage.
Any help would be great!
JShor
09-05-2011, 11:18 AM
Then you would have to rewrite that same condition to accept the value of both, as well as backstageworker from shade.
if($_POST[shade] == 'Backstageworker' || $_POST[shade] == 'Both') {
keyboard
09-05-2011, 08:46 PM
Thanks JShor. When I select sound or setmover, $type still prints Backstage.
<html>
<head>
<script>
var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}
function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to submit form")
return false
}
}
}
</script>
<script language="javascript">
function disableField()
{
document.getElementById('checky').disabled = false;
}
</script>
</head>
<body>
<body style="background-color:lightgreen">
<?php
require "database.php";
//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'] | !$_POST['firstname'] | !$_POST['lastname'] | !$_POST['age'] | !$_POST['gender'] | !$_POST['email'] )
{
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[shade] == 'Backstageworker' || $_POST[shade] == 'Both') {
$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 $type;
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']; ?>" name="agreeform" onSubmit="return defaultagree(this)" 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="20">
</td></tr>
<tr><td>Confirm Password:</td><td>
<input type="password" name="pass2" maxlength="20">
</td></tr>
<tr><td>First name:</td><td>
<input name="firstname" type="text" maxlength="15">
</td></tr>
<tr><td>Last name:</td><td>
<input name="lastname" type="text" maxlength="15">
</td></tr>
<tr><td>Age:</td><td>
<select name="age">
<?php $i = 1; while($i <= 110) { echo "<option value=\"$i\">$i</option>"; $i++; } ?>
</select>
<tr><td>Gender:</td><td>
<input type="radio" name="gender" value="Male" id="Male">Male
<input type="radio" name="gender" value="Female" id="Female">Female <br />
</td></tr>
<tr><td>Email:</td><td>
<input name="email" type="text" maxlength="30">
</td></tr>
<tr><td>Are you interested in backstage work or onstage?:</td><td>
<input type="radio" name="shade" value="Actor" id="actor" onclick="chgType()">Actor
<input type="radio" name="shade" value="Backstage" id="backstage" onclick="chgType()">Backstage worker
<input type="radio" name="shade" value="Both" id="both" onclick="chgType()">Both<br />
<select name="typeSelector" id="typeSelector" style="visibility: hidden">
<option>Set mover</option>
<option>Sound</option>
</select>
<br /><br /><br />
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)" id="checky" disabled="true"><b>I agree to the <a href="terms.php" onclick="disableField()" target="_blank">terms and conditions</a></b><br>
</td></tr>
<tr><th colspan="2"><input type="submit" name="submit" value="Register" disabled></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>
keyboard
09-07-2011, 09:33 PM
Anyone?
JShor
09-08-2011, 03:04 AM
Try changing that line to this:
if($_POST[shade] == 'Backstage' || $_POST[shade] == 'Both') {
Because Backstage is the value of the radio button, not Backstageworker as it was in the code.
keyboard
09-08-2011, 04:06 AM
Yep, it's working now. Thanks JShor!
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.