Announcement

Collapse
No announcement yet.

Help with PHP coding please!

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with PHP coding please!

    In the image at the bottom of this post is the current registration form for The Tube Station...

    I'd like to cut this down to the top four fields ONLY!

    IE - username, Password and password verification then Email address.

    The rest of the stuff is rubbish that I don't need to know!

    If someone can rewrite this code for me I'd be very grateful.

    I have tried several times myself but I can't seem to do it correctly.

    I can remove the unwanted fields but for some reason the registration process won't work!

    CODE[/quote]
    <?php
    unset($string);


    if(isset($_POST['Submit'])){

    $username = strip_tags(mysql_real_escape_string($_REQUEST['use rname']));
    $pass1 = strip_tags(mysql_real_escape_string($_POST['pass1' ]));
    $pass2 = strip_tags(mysql_real_escape_string($_POST['pass2' ]));
    $email = strip_tags(mysql_real_escape_string($_REQUEST['ema il']));
    $birthmo = strip_tags(mysql_real_escape_string($_REQUEST['bir thmo']));
    $birthda = strip_tags(mysql_real_escape_string($_REQUEST['bir thda']));
    $birthyr = strip_tags(mysql_real_escape_string($_REQUEST['bir thyr']));
    $gender = strip_tags(mysql_real_escape_string($_REQUEST['gen der']));
    $orientation = strip_tags(mysql_real_escape_string($_REQUEST['ori entation']));
    $marital = strip_tags(mysql_real_escape_string($_REQUEST['mar ital']));
    $city = strip_tags(mysql_real_escape_string($_REQUEST['cit y']));
    $country = strip_tags(mysql_real_escape_string($_REQUEST['cou ntry']));

    // strip all characters from username except alphanumeric and underscore
    $username = $username;
    $username = ereg_replace("[^A-Za-z0-9_]", "", $username);

    // strip all characters from password except alphanumeric and underscore
    $pass1 = $pass1;
    $pass1 = ereg_replace("[^A-Za-z0-9_]", "", $pass1);

    //error checking

    //make sure username is unique
    $sqlus = mysql_query("SELECT count(*) as num FROM users WHERE username = '$username'", $conn);
    $us = mysql_fetch_array( $sqlus, MYSQL_ASSOC );

    if($us[num]>0){
    $err_fld_username_taken = "<span class=\"errormsg\">Username already Taken! Please choose another.</span>";
    $error = 1;
    }

    //make sure email is unique
    $sqlus = mysql_query("SELECT count(*) as num FROM users WHERE email = '$email' AND (status = 'active' OR status = 'banned')", $conn);
    $us = mysql_fetch_array( $sqlus, MYSQL_ASSOC );

    if($us[num]>0){
    $err_fld_email_taken = "<br /><span class=\"errormsg\">Email already in use! Please enter another.</span>";
    $error = 1;
    }

    if (strlen($pass1)<1) {
    $err_fld_pass_empty = "<br /><span class=\"errormsg\">Please enter a password.</span>";
    $error = 1;
    }

    if ($pass1 != $pass2) {
    $err_fld_pass_match = "<br /><span class=\"errormsg\">Passwords don't match. Please try again.</span>";
    $error = 1;
    }

    if (strlen($pass1)<6 || strlen($pass1)>20) {
    $err_fld_pass_length = "<br /><span class=\"errormsg\">Password must be between 6-20 characters.</span>";
    $error = 1;
    }

    if (strlen($username)<6 || strlen($username)>20) {
    $err_fld_username_length = "<br /><span class=\"errormsg\">Username must be between 6-20 characters.</span>";
    $error = 1;
    }

    if(!preg_match('([a-zA-Z0-9\.\-\_]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z])' , $email)){
    $err_fld_email = "<br /><span class=\"errormsg\">Email address invalid.</span>";
    $error = 1;
    }

    if (strlen($birthmo)<1) {
    $err_fld_birthmo = "<br /><span class=\"errormsg\">Please select your Birth Month.</span>";
    $error = 1;
    }

    if (strlen($birthda)<1) {
    $err_fld_birthda = "<br /><span class=\"errormsg\">Please select your Birth Day.</span>";
    $error = 1;
    }

    if (strlen($birthyr)<1) {
    $err_fld_birthyr = "<br /><span class=\"errormsg\">Please select your Birth Year.</span>";
    $error = 1;
    }

    if (strlen($gender)<1) {
    $err_fld_gender = "<br /><span class=\"errormsg\">Please select your Gender.</span>";
    $error = 1;
    }

    if (strlen($orientation)<1) {
    $err_fld_orientation = "<br /><span class=\"errormsg\">Please select your Orientation.</span>";
    $error = 1;
    }

    if (strlen($marital)<1) {
    $err_fld_marital = "<br /><span class=\"errormsg\">Please select your Relationship Status.</span>";
    $error = 1;
    }

    if (strlen($city)<1) {
    $err_fld_city = "<br /><span class=\"errormsg\">Please enter your City.</span>";
    $error = 1;
    }

    if (strlen($country)<1) {
    $err_fld_country = "<br /><span class=\"errormsg\">Please enter your Country.</span>";
    $error = 1;
    }

    if($set[captcha_reg]==1){
    // captcha
    include("../../captcha/securimage.php");
    $img = new Securimage();
    $valid = $img->check($_POST['code']);

    if($valid == true) {
    //echo "<center>Thanks, you entered the correct code.</center>";
    } else {
    $err_fld_code = "<br /><span class=\"errormsg\">The code you entered was invalid. Try again. </span>";
    $error = 1;
    }
    } else {
    $valid = true;
    }

    if(!$error){

    $datetime = date ("Y-m-d H:i:s");

    // Generate a random salt
    $salt = substr(md5(uniqid(rand(), true)), 0, 5);

    // Hash password
    $secure_password = md5($salt . md5($pass1));

    //insert
    $sql = "INSERT INTO users VALUES ('?','active','$datetime','$datetime','1','$userna me','$secure_password','$salt','$email','0','1','1 ','','','','1','$gender','$birthmo','$birthda','$b irthyr','$orientation','$marital','$city','$countr y','','','','','','')";
    $result = mysql_query($sql, $conn);

    // send email

    $string = "Thank You for registering!";

    if($set[validate_email]==1){
    $string.= "\nYou must validate your email address $email before you can login. Check your email and click the ";
    $string.= "validation link.";

    $key = md5($datetime . $email);
    $validate_link = "$set[home_url]/validate.php?key=$key&email=$email&a=v";
    }

    $subject = str_replace("{site_title}", $set[site_title], $set[reg_email_subject]);

    $message = str_replace("{validate_link}", $validate_link, $set[reg_email_body]);
    $message = str_replace("{username}", $username, $message);
    $message = str_replace("{password}", $pass1, $message);
    $message = str_replace("{site_title}", $set[site_title], $message);
    $message = str_replace("{admin_email}", $set[admin_email], $message);


    mail( "{$_REQUEST['email']}", $subject, $message, "From: $set[replyto_email]" );

    if($set['validate_email']==0){

    //register session
    session_start();
    $_SESSION["TubeUser"] = "$username";

    //set cookie for 30 days
    setcookie("TubeCookie", $username, time()+60*60*24*30,"/", $set[cookie_domain]);

    }
    }

    }

    if(!isset($_POST['Submit']) || $error==1){

    $username = strip_tags(mysql_real_escape_string($_POST['userna me']));
    $email = strip_tags(mysql_real_escape_string($_POST['email' ]));
    $birthmo = strip_tags(mysql_real_escape_string($_POST['birthm o']));
    $birthda = strip_tags(mysql_real_escape_string($_POST['birthd a']));
    $birthyr = strip_tags(mysql_real_escape_string($_POST['birthy r']));
    $gender = strip_tags(mysql_real_escape_string($_POST['gender ']));
    $orientation = strip_tags(mysql_real_escape_string($_POST['orient ation']));
    $marital = strip_tags(mysql_real_escape_string($_POST['marita l']));
    $city = strip_tags(mysql_real_escape_string($_POST['city'] ));
    $country = strip_tags(mysql_real_escape_string($_POST['countr y']));


    $string.="
    <form name=\"form1\" action=\"../register/\" method=\"post\">
    <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    <tr>
    <td>Username:</td>
    <td><input name=\"username\" type=\"text\" maxlength=\"20\" value=\"$username\"> 6-20 characters $err_fld_username_taken $err_fld_username_length</td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input name=\"pass1\" type=\"password\" maxlength=\"20\"> 6-20 characters $err_fld_pass_match $err_fld_pass_empty $err_fld_pass_lenght</td>
    </tr>
    <tr>
    <td>Password Again:</td>
    <td><input name=\"pass2\" type=\"password\" maxlength=\"20\"></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input name=\"email\" type=\"text\" maxlength=\"255\" value=\"$email\"> $err_fld_email $err_fld_email_taken</td>
    </tr>


    <tr>
    <td>Birthdate:</td>
    <td>
    <select name=\"birthmo\" id=\"birthmo\">\n";

    if(strlen($birthmo)<1){

    $string.="<option value=\"\">Select</option>";

    } else {

    $mo = date("F", strtotime("$birthmo/01/2000"));
    $string.="<option value=\"$birthmo\" selected=\"selected\">$mo</option>\n";

    }

    $string.="
    <option value=\"1\">January</option>\n
    <option value=\"2\">February</option>\n
    <option value=\"3\">March</option>\n
    <option value=\"4\">April</option>\n
    <option value=\"5\">May</option>\n
    <option value=\"6\">June</option>\n
    <option value=\"7\">July</option>\n
    <option value=\"8\">August</option>\n
    <option value=\"9\">September</option>\n
    <option value=\"10\">October</option>\n
    <option value=\"11\">November</option>\n
    <option value=\"12\">December</option>\n
    </select>\n

    <select name=\"birthda\" id=\"birthda\">";

    if(strlen($birthda)<1){
    $string.="<option value=\"\">Select</option>";
    } else {
    $string.="<option selected=\"selected\">$birthda</option>\n";
    }

    for($i=1;$i<=31;$i++){
    $string.="<option>$i</option>";
    }

    $string.="
    </select>

    <select name=\"birthyr\" id=\"birthyr\">";

    if(strlen($birthyr)<1){

    $string.="<option value=\"\">Select</option>";

    } else {

    $string.="<option selected=\"selected\">$birthyr</option>\n";

    }

    $curryr = date("Y")-18;
    $lastyr = $curryr-100;

    for($i=$curryr;$i>=$lastyr;$i-=1){
    $string.="<option>$i</option>";
    }

    $string.="
    </select>

    $err_fld_birthmo
    $err_fld_birthda
    $err_fld_birthyr

    </td>
    </tr>


    <tr>
    <td>Gender:</td>
    <td>
    <select name=\"gender\">";

    if(strlen($gender)>0){

    if($gender=="m"){
    $string.="<option value=\"m\" selected=\"selected\">Male</option>";
    }
    if($gender=="f"){
    $string.="<option value=\"f\" selected=\"selected\">Female</option>";
    }
    if($gender=="c"){
    $string.="<option value=\"c\" selected=\"selected\">Couple</option>";
    }
    if($gender=="t"){
    $string.="<option value=\"t\" selected=\"selected\">Transgender</option>";
    }
    if($gender=="x"){
    $string.="<option value=\"x\" selected=\"selected\">Prefer not to disclose</option>";
    }

    } else {
    $string.="<option value=\"\">Select</option>";
    }

    $string.="
    <option value=\"m\">Male</option>
    <option value=\"f\">Female</option>
    <option value=\"c\">Couple</option>
    <option value=\"t\">Transgender</option>
    <option value=\"x\">Prefer not to disclose</option>
    </select>\n
    $err_fld_gender</td>
    </tr>

    <tr>
    <td>Orientation:</td>
    <td>
    <select name=\"orientation\">";


    if(strlen($orientation)>0){

    if($orientation=="s"){
    $string.="<option value=\"s\" selected=\"selected\">Straight</option>";
    }
    if($orientation=="g"){
    $string.="<option value=\"g\" selected=\"selected\">Gay / Lesbian</option>";
    }
    if($orientation=="b"){
    $string.="<option value=\"b\" selected=\"selected\">Bisexual</option>";
    }
    if($orientation=="x"){
    $string.="<option value=\"x\" selected=\"selected\">Prefer not to disclose</option>";
    }

    } else {
    $string.="<option value=\"\">Select</option>";
    }

    $string.="
    <option value=\"s\">Straight</option>
    <option value=\"g\">Gay / Lesbian</option>
    <option value=\"b\">Bisexual</option>
    <option value=\"x\">Prefer not to disclose</option>
    </select>\n

    $err_fld_orientation</td>
    </tr>

    <tr>
    <td>Relationship Status:</td>
    <td>
    <select name=\"marital\">";

    if(strlen($marital)>0){

    if($marital=="s"){
    $string.="<option value=\"s\" selected=\"selected\">Single</option>";
    }
    if($marital=="m"){
    $string.="<option value=\"m\" selected=\"selected\">Married</option>";
    }
    if($marital=="r"){
    $string.="<option value=\"r\" selected=\"selected\">In a relationship</option>";
    }
    if($marital=="x"){
    $string.="<option value=\"x\" selected=\"selected\">Prefer not to disclose</option>";
    }

    } else {
    $string.="<option value=\"\">Select</option>";
    }


    $string.="
    <option value=\"s\">Single</option>
    <option value=\"m\">Married</option>
    <option value=\"r\">In a relationship</option>
    <option value=\"x\">Prefer not to disclose</option>
    </select>\n


    $err_fld_marital</td>
    </tr>

    <tr>
    <td>City:</td>
    <td><input name=\"city\" type=\"text\" maxlength=\"255\" value=\"$city\"> $err_fld_city</td>
    </tr>

    <tr>
    <td>Country:</td>
    <td><select name=\"country\">";

    if(strlen($country)>0){

    $sqlco = mysql_query("SELECT * FROM country WHERE iso = '$country'", $conn);
    $co = mysql_fetch_array( $sqlco, MYSQL_ASSOC );

    $string.="<option value=\"$co[iso]\" selected=\"selected\">$co[printable_name]</option>";

    } else {
    $string.="<option value=\"\">Select</option>";
    }


    $sqlco = mysql_query("SELECT * FROM country ORDER BY name", $conn);
    while($co = mysql_fetch_array( $sqlco, MYSQL_ASSOC )){

    $string.="<option value=\"$co[iso]\">$co[printable_name]</option>\n";

    }

    $string.="</select>\n
    $err_fld_country</td>
    </tr>";

    if($set[captcha_reg]==1){

    $sid = md5(uniqid(time()));

    $string.="
    <tr>
    <td>Enter Code:</td>
    <td>
    <img src=\"$set[home_url]/captcha/securimage_show.php?sid=$sid\"><br />\n

    <input type=\"text\" name=\"code\" id=\"code\"/>$err_fld_code</td>\n";

    }

    $string.="

    <tr>
    <td></td>
    <td><input class=\"button\" name=\"Submit\" type=\"submit\" value=\"Register Now!\"></td>
    </tr>
    </table></form>
    ";


    }


    ?>[/quote]
    Attached Files
    SHEMALE.CENTER
    World's Greatest Tgirl Cam Site.

  • #2
    try with that:

    IF it fails, then use phpmyadmin to edit the structure of table "users" and change all fields to allow NULL values, except the 4 required fields.

    CODE[/quote]
    <?php
    unset($string);


    if(isset($_POST['Submit'])){

    $username = strip_tags(mysql_real_escape_string($_REQUEST['use rname']));
    $pass1 = strip_tags(mysql_real_escape_string($_POST['pass1' ]));
    $pass2 = strip_tags(mysql_real_escape_string($_POST['pass2' ]));
    $email = strip_tags(mysql_real_escape_string($_REQUEST['ema il']));

    // strip all characters from username except alphanumeric and underscore
    $username = $username;
    $username = ereg_replace("[^A-Za-z0-9_]", "", $username);

    // strip all characters from password except alphanumeric and underscore
    $pass1 = $pass1;
    $pass1 = ereg_replace("[^A-Za-z0-9_]", "", $pass1);

    //error checking

    //make sure username is unique
    $sqlus = mysql_query("SELECT count(*) as num FROM users WHERE username = '$username'", $conn);
    $us = mysql_fetch_array( $sqlus, MYSQL_ASSOC );

    if($us[num]>0){
    $err_fld_username_taken = "<span class=\"errormsg\">Username already Taken! Please choose another.</span>";
    $error = 1;
    }

    //make sure email is unique
    $sqlus = mysql_query("SELECT count(*) as num FROM users WHERE email = '$email' AND (status = 'active' OR status = 'banned')", $conn);
    $us = mysql_fetch_array( $sqlus, MYSQL_ASSOC );

    if($us[num]>0){
    $err_fld_email_taken = "<br /><span class=\"errormsg\">Email already in use! Please enter another.</span>";
    $error = 1;
    }

    if (strlen($pass1)<1) {
    $err_fld_pass_empty = "<br /><span class=\"errormsg\">Please enter a password.</span>";
    $error = 1;
    }

    if ($pass1 != $pass2) {
    $err_fld_pass_match = "<br /><span class=\"errormsg\">Passwords don't match. Please try again.</span>";
    $error = 1;
    }

    if (strlen($pass1)<6 || strlen($pass1)>20) {
    $err_fld_pass_length = "<br /><span class=\"errormsg\">Password must be between 6-20 characters.</span>";
    $error = 1;
    }

    if (strlen($username)<6 || strlen($username)>20) {
    $err_fld_username_length = "<br /><span class=\"errormsg\">Username must be between 6-20 characters.</span>";
    $error = 1;
    }

    if(!preg_match('([a-zA-Z0-9\.\-\_]+\@[a-zA-Z0-9\.\-]+\.[a-zA-Z])' , $email)){
    $err_fld_email = "<br /><span class=\"errormsg\">Email address invalid.</span>";
    $error = 1;
    }

    if($set[captcha_reg]==1){
    // captcha
    include("../../captcha/securimage.php");
    $img = new Securimage();
    $valid = $img->check($_POST['code']);

    if($valid == true) {
    //echo "<center>Thanks, you entered the correct code.</center>";
    } else {
    $err_fld_code = "<br /><span class=\"errormsg\">The code you entered was invalid. Try again. </span>";
    $error = 1;
    }
    } else {
    $valid = true;
    }

    if(!$error){

    $datetime = date ("Y-m-d H:i:s");

    // Generate a random salt
    $salt = substr(md5(uniqid(rand(), true)), 0, 5);

    // Hash password
    $secure_password = md5($salt . md5($pass1));

    //insert
    $sql = "INSERT INTO users VALUES ('?','active','$datetime','$datetime','1','$userna me','$secure_password','$salt','$email','0','1','1 ','','','','1','$gender','$birthmo','$birthda','$b irthyr','$orientation','$marital','$city','$countr y','','','','','','')";
    $result = mysql_query($sql, $conn);

    // send email

    $string = "Thank You for registering!";

    if($set[validate_email]==1){
    $string.= "\nYou must validate your email address $email before you can login. Check your email and click the ";
    $string.= "validation link.";

    $key = md5($datetime . $email);
    $validate_link = "$set[home_url]/validate.php?key=$key&email=$email&a=v";
    }

    $subject = str_replace("{site_title}", $set[site_title], $set[reg_email_subject]);

    $message = str_replace("{validate_link}", $validate_link, $set[reg_email_body]);
    $message = str_replace("{username}", $username, $message);
    $message = str_replace("{password}", $pass1, $message);
    $message = str_replace("{site_title}", $set[site_title], $message);
    $message = str_replace("{admin_email}", $set[admin_email], $message);


    mail( "{$_REQUEST['email']}", $subject, $message, "From: $set[replyto_email]" );

    if($set['validate_email']==0){

    //register session
    session_start();
    $_SESSION["TubeUser"] = "$username";

    //set cookie for 30 days
    setcookie("TubeCookie", $username, time()+60*60*24*30,"/", $set[cookie_domain]);

    }
    }

    }

    if(!isset($_POST['Submit']) || $error==1){

    $username = strip_tags(mysql_real_escape_string($_POST['userna me']));
    $email = strip_tags(mysql_real_escape_string($_POST['email' ]));

    $string.="
    <form name=\"form1\" action=\"../register/\" method=\"post\">
    <table border=\"0\" cellspacing=\"0\" cellpadding=\"4\">
    <tr>
    <td>Username:</td>
    <td><input name=\"username\" type=\"text\" maxlength=\"20\" value=\"$username\"> 6-20 characters $err_fld_username_taken $err_fld_username_length</td>
    </tr>
    <tr>
    <td>Password:</td>
    <td><input name=\"pass1\" type=\"password\" maxlength=\"20\"> 6-20 characters $err_fld_pass_match $err_fld_pass_empty $err_fld_pass_lenght</td>
    </tr>
    <tr>
    <td>Password Again:</td>
    <td><input name=\"pass2\" type=\"password\" maxlength=\"20\"></td>
    </tr>
    <tr>
    <td>Email:</td>
    <td><input name=\"email\" type=\"text\" maxlength=\"255\" value=\"$email\"> $err_fld_email $err_fld_email_taken</td>
    </tr>

    }


    if($set[captcha_reg]==1){

    $sid = md5(uniqid(time()));

    $string.="
    <tr>
    <td>Enter Code:</td>
    <td>
    <img src=\"$set[home_url]/captcha/securimage_show.php?sid=$sid\"><br />\n

    <input type=\"text\" name=\"code\" id=\"code\"/>$err_fld_code</td>\n";

    }

    $string.="

    <tr>
    <td></td>
    <td><input class=\"button\" name=\"Submit\" type=\"submit\" value=\"Register Now!\"></td>
    </tr>
    </table></form>
    ";

    }


    ?>[/quote]

    Comment


    • #3
      Thanks... I'll give that code a go and let you know if it works...

      Cheers...
      SHEMALE.CENTER
      World's Greatest Tgirl Cam Site.

      Comment


      • #4
        Well that code looked like the same page... But I've been having a stab at it and I may have cracked it!
        SHEMALE.CENTER
        World's Greatest Tgirl Cam Site.

        Comment



        Working...
        X