Web Hosting Forum | Lunarpages


*
Welcome, Guest. Please login or register.
Did you miss your activation email?



Login with username, password and session length
May 24, 2012, 11:48:19 AM

Pages: [1]   Go Down
  Print  
Author Topic: HELP! Issues with form processing code  (Read 373 times)
jonhoeft
Newbie
*
Offline Offline

Posts: 3


« on: January 02, 2012, 07:32:20 PM »

I have several issues. My first issue is, I want to make a registration page that only people that I give the pin to can register, but I don't know how to do that. The second issue is, I want to create a file upload form so my students can upload their assignments to the server, and then I can download them onto my computer. I know how to make the form but I don't know how to make it work. The final issue is, the way I have it set to log the user out doesn't actually log the user out. Can somebody please help me out?
Logged
wektech
Master Jedi
*****
Offline Offline

Posts: 1031



WWW
« Reply #1 on: January 03, 2012, 09:47:31 AM »

Are you looking to modify an existing script to add functionality or are you building all the code from scratch? Adding php code to validate a single "pin" field is fairly simple:

Code:
$formurl = "register.htm" ;
$pincorrect = "no";

if ($_REQUEST["pin"] == "12345")
{$pincorrect = "yes"}
else
{ header( "Location: $formurl" );
exit ; }

in this example, If the user does not enter the correct pin they are sent to page register.htm otherwise the variable !pincorrect is set to yes

Logged

jonhoeft
Newbie
*
Offline Offline

Posts: 3


« Reply #2 on: January 03, 2012, 11:18:31 AM »

I created every thing from scratch. What I want is for the user to register with username, email, and their own password, but I only want people who have the passphrase/pin Tibet able to register. Would it help if I posted a link to the site or posted the code?
Logged
wektech
Master Jedi
*****
Offline Offline

Posts: 1031



WWW
« Reply #3 on: January 04, 2012, 10:45:23 AM »

So the registration code is in place? If so then you just need to add an input area on the form to add the pin. You could then add something to the very first line of the form processing page along the lines of:
Code:
$formurl = "register.htm" ;
if ($_REQUEST["pin"]<>"Tibet")
{ header( "Location: $formurl" );
exit ; }
This just sends the user back to the form to try again, otherwise it proceeds with the rest of the form processing code. There could be more elegant ways to do  this but I would need to see the registration form and the registration form processing code.
Logged

jonhoeft
Newbie
*
Offline Offline

Posts: 3


« Reply #4 on: January 04, 2012, 10:55:46 AM »

Here is the form code
Code:
    <form action="registration.php" method="post">
  <table width="400" border="0" align="center">
    <tr>
      <td><label>Full Name: </label></td>
      <td><input type="text" name="full_name" id="full_name" /></td>
    </tr>
    <tr>
      <td><label>Email Address: </label>
      </td>
      <td><input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <td><label>Username:</label></td>
      <td><input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
      <td><label>Password: </label>&nbsp;</td>
      <td><input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
      <td><label>Would you like to receive a monthly Newsletter?</label></td>
      <td><select name="newsletter" id="newsletter">
        <option value="blank"></option>
        <option value="yes">Yes</option>
        <option value="no">No</option>
      </select></td>
    </tr>
    <tr class="ctr">
      <td colspan="2"><input name="submit" type="submit" id="submit" value="Register" /></td>
    </tr>
  </table>
</form>

Form processing code
Code:
$myusername = $_POST['username'];
$myemail = $_POST['email'];
$mypassword = $_POST['password'];
$full_name = $_POST['full_name'];
$username = $_POST['username'];
$password = sha1($_POST['password']);
$passphrase = sha1($_POST['passphrase']);
$email = sha1($_POST['email']);
$newsletter - $_POST['newsletter'];

$website = "http://www.jennifermccurley.org/login.html";

$to = $myemail;
$subject = "Registration Confirmation";
$headers = 'From: webmaster@jennifermccurley.org' . "\r\n";

$message = "Dear $full_name," . "\r\n";
$message .= 'Thank you for registering to use Mrs. McCurley\'s class portal.' . "\r\n";
$message .= "Username: '$myusername'" . "\r\n";
$message .= "password: '$mypassword'" . "\r\n";
$message .= 'Please use the username and password above to access the portal.' . "\r\n";
$message .= $website . "\r\n";
//echo $subject . "<br />";
//echo $headers . "<br />";
//echo $message . "<br />";

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

 if($username_exist > 0){
  echo "The username you specified has already been taken.  Please choose another one.";
  unset($username);
  include 'registration_form.html';
  exit();
}


$query = "INSERT INTO users (full_name, username, password, email, newsletter)
VALUES('$full_name', '$username', '$password', '$email', '$newsletter')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "Hi, $full_name, you are now registered to access our website.";
echo "<br>";
echo "Your username and password will be sent to you at $email.";
mail($to, $subject, $message, $headers);
?>
Logged
wektech
Master Jedi
*****
Offline Offline

Posts: 1031



WWW
« Reply #5 on: January 04, 2012, 11:49:34 AM »

I believe the following would work:

Code:
  <form action="registration.php" method="post">
  <table width="400" border="0" align="center">
    <tr>
      <td><label>Full Name: </label></td>
      <td><input type="text" name="full_name" id="full_name" /></td>
    </tr>
    <tr>
      <td><label>Email Address: </label>
      </td>
      <td><input type="text" name="email" id="email" /></td>
    </tr>
    <tr>
      <td><label>Username:</label></td>
      <td><input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
      <td><label>Password: </label>&nbsp;</td>
      <td><input type="password" name="password" id="password" /></td>
    </tr>
  <tr>
      <td><label>Secret Pin: </label>&nbsp;</td>
      <td><input type="text" name="pinword" id="pinword" /></td>
    </tr>
    <tr>
      <td><label>Would you like to receive a monthly Newsletter?</label></td>
      <td><select name="newsletter" id="newsletter">
        <option value="blank"></option>
        <option value="yes">Yes</option>
        <option value="no">No</option>
      </select></td>
    </tr>
    <tr class="ctr">
      <td colspan="2"><input name="submit" type="submit" id="submit" value="Register" /></td>
    </tr>
  </table>
</form>

and process it as follows:
Code:
$myusername = $_POST['username'];
$myemail = $_POST['email'];
$mypassword = $_POST['password'];
$full_name = $_POST['full_name'];
$username = $_POST['username'];
$password = sha1($_POST['password']);
$passphrase = sha1($_POST['passphrase']);
$email = sha1($_POST['email']);
$newsletter - $_POST['newsletter'];
$pinword - $_POST['pinword'];
$website = "http://www.jennifermccurley.org/login.html";

$to = $myemail;
$subject = "Registration Confirmation";
$headers = 'From: webmaster@jennifermccurley.org' . "\r\n";

$message = "Dear $full_name," . "\r\n";
$message .= 'Thank you for registering to use Mrs. McCurley\'s class portal.' . "\r\n";
$message .= "Username: '$myusername'" . "\r\n";
$message .= "password: '$mypassword'" . "\r\n";
$message .= 'Please use the username and password above to access the portal.' . "\r\n";
$message .= $website . "\r\n";
//echo $subject . "<br />";
//echo $headers . "<br />";
//echo $message . "<br />";

$checkuser = mysql_query("SELECT username FROM users WHERE username='$username'");

$username_exist = mysql_num_rows($checkuser);

if($username_exist > 0){
  echo "The username you specified has already been taken.  Please choose another one.";
  unset($username);
  include 'registration_form.html';
  exit();
}
 if($pinword  <> "Tibet"){
  echo "The Secret Pin you specified is incorrect, please try again!.";
  unset($pinword);
  include 'registration_form.html';
  exit();
}
 
$query = "INSERT INTO users (full_name, username, password, email, newsletter)
VALUES('$full_name', '$username', '$password', '$email', '$newsletter')";
mysql_query($query) or die(mysql_error());
mysql_close();

echo "Hi, $full_name, you are now registered to access our website.";
echo "<br>";
echo "Your username and password will be sent to you at $email.";
mail($to, $subject, $message, $headers);
?>
Logged

Pages: [1]   Go Up
  Print  
 
Jump to: