Jump to content

First Post, New PHP User, May need Mentor


neverbegosu

Recommended Posts

Hey fellas, and ladies, and all you other php wize's.  Names mike and I'm new to php and mysql.  Ive done alot of self study but have no formal training at all.  I am pretty much just winging my code from w3 schools and other php online codeing helps.  I am currently making a registration script for my site, and have hit a bit of a snag.  Her is the current code for my regpass.php.

 

<?php

include('srvdbcon.php');

 

$NewUserNameTest=$_POST['NewUserName'];

if(!ereg('[^A-Za-z0-9]',$NewUserNameTest))

    {

    $query="SELECT * FROM user WHERE user ='$_POST(NewUserName)'";

    $result=mysql_query($query);

    $num=mysql_num_rows($result);

    if($num == 0)

          {

  $query2="SELECT * FROM user WHERE email ='$_POST(NewUserEmail)'";

          $result2=mysql_query($query2);

          $num2=mysql_num_rows($result2);

  if ($num2 == 0)

              {

      if(($_POST[NewUserPw]==$_POST[NewUserPwCon])&&($_POST[NewUserEmail]==$_POST[NewUserEmailCon]))

                    {

                    //Create a random code

                    $confirm_code=md5(uniqid(rand()));

                    //HACK PREVENTION

                    $name=strip_tags($_POST['NewUserName']);

                    $email=strip_tags($_POST['NewUserEmail']);

                    $pw=strip_tags($_POST['NewUserPw']);

                    //Insert Information Into Temp Code

                    $sql="INSERT INTO temp SET code='$confirm_code',user='$name', email='$email', password='$pw'";

                    $result=mysql_query($sql);

    if($result)

                        {

                  $message="SCG.O Confirmation \r\n";

                  $message="Enter this confirmation code into confirmation page.\r\n";

                  $message="Enter code into confirmation: $confirm_code";

                  $sentmail=mail("$email",'Registration Confirmation',"$message",'From: SCGAdmin@uprisetechnology.com');

                  header("Location:index.php");

                  }

                      else

                            {

                            die ("Something went wrong.");

                            }

    }

                    else

                    {

                    die("Password And / Or Email does not match the confirmation entry");

                    }

      }

              else

              {

              die("Email Already in Use");

              }

          }

          else

          {

          die("Username already in use");

          }

    }

    else

    {

    die("Username includes Bad Characters.");

    }

?>

 

 

 

----------------------------------------------------------------------------

The problem I am having is the code executes up to Confirming email and password with the confirming.  I have checked, and double checked, the names of the variables $NewUserEmail $NewUserEmailCon $NewUserPw $NewUserPwCon      When I click the register button it runs the regpass.php but I am getting the Die results for Error with matching confirmations.

 

Any help would be appreciated.  I know it is not the neatest codeing, nor is it probably logical to more vast programmers, but I am learning, and programming accourding to my own logic so I can understand it.  Thanks.  The code does not post anything to the mysql db but everything else is set up properly.  The DB works, I have created this kind of script before with help from others, but this one is using my logic so I can understand the code.

Thanks again.

NeverBeGosu

Link to comment
Share on other sites

some of us have jobs.

 

suggestion: always check the results of your SQL queries and view the SQL you are executing.

 

$query="SELECT * FROM user WHERE user ='$_POST(NewUserName)'";
$result=mysql_query($query) or die(mysql_error() . " IN $query");

 

I agree with BlueSky on this. It is very important to check your requests. To add, it helps to echo out your variables while testing, and also don't forget to check your mail functions as well.

 

Here's what I do when I have a query that is not working...

 

1. echo out your sql statement, so you can see what it looks like after php parses it

2. enter it into the SQL code window in your phpMyAdmin

 

If it works in your phpMyAdmin chances are you are not escaping something or missing ' ' around a value.

 

I wish I had time to put your code into production and test, but I don't right now.

I will check on it later and if you are still hunting I will be happy to provide more help when time allows.

 

:)

Link to comment
Share on other sites

the code i provided for my posting to db works fine, I tested it on other script.  Post fine to db.  I just cant figure out where the error is before that.  The code provided doesnt even reach the point of posting to sql.  Its erroring at the confirmation email and password check, and I cant figure out why.

Link to comment
Share on other sites

Just before the line where you do the comparison add this code and run the script again:

 

echo "NewUserPass: {$_POST['NewUserPw']} \n";
echo "NewUserPwCon: {$_POST['NewUserPwCon']} \n";
echo "NewUserEmail: {$_POST['NewUserEmail']} \n";
echo "NewUserEmailCon: {$_POST['NewUserEmailCon']} \n";
exit;

 

That way you can see what's in the variables and make sure you're getting what you should be getting, if that is the place the script is failing then that's the best place to start looking :)

 

Also, just noticed - you don't have single quotes around the names of the keys in your POST variables - I'm guessing that's just in the forum post but if it's in your code it will not be helping at all.

 

HTH

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.