13:59 Mon Sep  3, 2007
Cheap Hummer!

12:18 Tue Jul  4, 2006
Hummer Camp After

12:15 Tue Jul  4, 2006
Hummer Camp

Help Me Humpa
PHP and MMS Server Help
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Problems wth "Create user"...

 
Post new topic   Reply to topic    Help Me Humpa Forum Index -> Anything PHP
View previous topic :: View next topic  
Author Message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 05, 2006 1:29 pm    Post subject: Problems wth "Create user"... Reply with quote

Hey Smile

I was trying to edit a file at work last night and was working on the server thru my CPanel. I always make a copy of the file rather than work on the original and I tried to do this, but somehow, I managed to delete the original file - and ended up with no copy of it Sad So basically, somehow I've been a bit of a dick. I've found what I thought was the original file, but for some reason it doesn't work. I don't get any errors, but when I fill in the details and then hit "Create Account", it just reloads the script. When you've got a spare 5, could you please run your keen eye over it and perhaps let me know what I'm doing wrong?

create.php:
Code:

<LINK REL="StyleSheet" HREF="style_new.css" TYPE="text/css">

<?php
include( "config.php" );

function isFaulty( $nick, $email, $pwd1, $pwd2, &$msg )
{
   if ( !strpos( $email, "@" ) )
   {
      $msg = "You must specify a valid email address!";
      return TRUE;
   }

   if ( $pwd1 != $pwd2 )
   {
      $msg = "Your two passwords did not match!";
      return TRUE;
   }

   $query = "SELECT id FROM users WHERE nickname='$nick'";
   $result = mysql_query( $query );
   $nres = mysql_num_rows( $result );
   if ( $nres != 0 )
   {
      $msg = "The nickname $nick is already in use by another user";
      return TRUE;
   }
   return FALSE;
}

function mkpasswd()
{
   srand( (double) microtime() * 1000000 );
   $unique_str = md5( rand( 0, 9999999 ) );
   return substr( $unique_str, 0, 8 );
}

function sendWelcomeMsg( $to, $nick, $pwd, $pwd1, $uid )
{
   $text = "Welcome!\n".
      "\n".
      "Your personal details\n".
      "---------------------\n".
      "Your nickname:                  $nick\n".
      "How to setup your phone\n".
      "-----------------------\n".
      "In your MMS settings find the option that specifies your ".
      "MMS Server (some vendors refer to it as Home Page, others ".
      " as MMSC, Message Server or Service Center). It should be ".
      " a setting under MMS where you are to type in a URL.\n\n".
      "Once you have found that setting you type in the following ".
      "URL: http://" . MYDOMAIN . "/mms/send.php?username=$pwd\n\n".
      "\n".
      "Cheers,\n".MYADMIN_NAME;


   $headers = "From: phree@" . MYDOMAIN . "\r\n".
         "Bcc: " . MYADMIN_EMAIL . "\r\n";
   $ret = mail( $to, "[phree] Welcome $nick",
           $text, $headers );
}
?>

<html>
<head>
   <title>Registration</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <link rel=stylesheet type="text/css" href="style_new.css">
</head>
       <?php
      if ( isset($nick) && isset($email) )
      {
         $link = mysql_connect("localhost", "mms",MYSQL_PWD)
                   or die("Could not connect to database1");   
         mysql_select_db("mmsusers")
            or die( "Could not select databse2" );

         $error = isFaulty( $nick, $email, $pwd1, $pwd2,
                  $errmsg );

         if ( !$error )
         {
            $pwd = mkpasswd();
            $query = "INSERT INTO users VALUES " .
               "(NULL, '$nick', NOW(), NULL, NULL, ".
               "'$pwd', '$pwd1', 0, 0, 0, 0, '$fname',".
               "'$sname',".
               "'$country', '$homepage', '$email', '',".
               "0, 0, 0)";
            $result = mysql_query($query);
            print( mysql_error() );            

            sendWelcomeMsg( $email, $nick, $pwd, $pwd1,
                  mysql_insert_id() );
         

                print( "<h3>Welcome " . $nick . "!</h3>\n" );
                    print( "Your login details and info on how " .
                   "to setup your phone has been sent to".
                   " <i>" . $email . "</i>\n" );      
         }
      }

      if ( !(isset($nick) && isset($email)) || $error )
      {
         if ( $error )
         {
               print( "<b>Problems registering:</b> " .
               $errmsg . "<br><br>\n" );
         }
      ?>
      <h3 align="center">&nbsp;</h3>
   <h3>Create new user</h3>
      Thanks for choosing to register.
      This site is brought to you free of charge with no
      plans to ever charge you, the user.<br><br>
      
      Registration is quick and simple. The only required fields are
      <b><i>Nickname</i></b> and <b><i>Email address</i>
      </b>. Your email is needed only to send you your phone
      password, information on
      how to set your phone up and to check that you
      actually exist. The email will not be used for
           spamming, neither will it be sold to spammers or shown on
      the web page anywhere.<br><br>
   <form method="POST" action="create.php">
      Nickname<br>
      <input type="text" name="nick" <?php if (isset($nick)) print("value=\"$nick\""); ?> ><br><br>
      First name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Surname<br>
      <input type="text" name="fname" <?php if (isset($fname)) print("value=\"$fname\"");?>>
      
      <input type="text" name="sname" <?php if (isset($sname)) print("value=\"$sname\"");?>><br><br>
      Country<br>
      <input type="text" name="country" <?php if (isset($country)) print("value=\"$country\"");?><br><br>
      Home page<br>
      <input type="text" name="homepage" <?php if (isset($homepage)) print("value=\"$homepage\""); else print("value=\"http://\""); ?>><br><br>
      Email address<br>
      <input type="text" name="email" <?php if (isset($email)) print("value=\"$email\"");?>><br><br>
      <input type="submit" class="submit" value="Create account">
   </form>
   <?php
      }

    ?>

   
   <?php
   $link = mysql_connect("localhost", "mms",MYSQL_PWD)
                 or die("Could not connect to database3");
   mysql_select_db("mmsusers") or die( "Could not select databse4" );
   
   ?>
   
</body>
</html>


Cheers Humpa!

On a different note, I saw this today and thought of you...For the man who has everything, I give you........HUMMER Aftershave!
Back to top
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Wed Jul 05, 2006 4:21 pm    Post subject: Reply with quote

stick some echo lines in various places to see how far the code is getting ... that's what i do.

use echo "1. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";

And just paste that line in different places, starting with the isFaulty function (just put them on a line right before each "if" statement)

But use change the number, so you can tell which echo lines are showing, you know?
Just spread these out throughout your code:

echo "1. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
echo "2. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
echo "3. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
Back to top
View user's profile Send private message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 05, 2006 6:12 pm    Post subject: Reply with quote

Hiya,

ok..Tried that. Now when I go to the page, I get this at the top:

4. nick is and email is and pwd1 is and pwd2 is
6. nick is and email is and pwd1 is and pwd2 is

Echo 4 is the code that starts:
Code:

<?php

      if ( isset($nick) && isset($email) )
      {
         $link = mysql_connect("localhost", "mms",MYSQL_PWD)
                   or die("Could not connect to database1");   
         mysql_select_db("mmsusers")
            or die( "Could not select databse2" );

         $error = isFaulty( $nick, $email, $pwd1, $pwd2,
                  $errmsg );


and Echo 6 is the code that starts:
Code:

      if ( !(isset($nick) && isset($email)) || $error )
      {
         if ( $error )
         {
               print( "<b>Problems registering:</b> " .
               $errmsg . "<br><br>\n" );
         }
      ?>


Does this tell me there's a problem with these 2 parts of the code somewhere? Just to clear up, where I have the die statements saying:
"Could not connect to database1" and "Could not select databse2" - they are obviously pointing to the same database, it's just so I know which part of the code was causing the problem, if any.
Back to top
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Wed Jul 05, 2006 6:23 pm    Post subject: Reply with quote

what?

I have no idea what you are saying.

Show me the file with the echo lines in it, and paste in what displays on your browser when you try to create a user.
Back to top
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Wed Jul 05, 2006 6:24 pm    Post subject: Reply with quote

but the fact that the nick and email are empty should be telling us something ... by the way, the nick and email will be empty - but after you submit the form, then they should not be empty.
Back to top
View user's profile Send private message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 05, 2006 6:33 pm    Post subject: Reply with quote

Eek! Ok, here goes...This is what my file now looks like:

Code:

<LINK REL="StyleSheet" HREF="style_new.css" TYPE="text/css">

<?php
include( "config.php" );

function isFaulty( $nick, $email, $pwd1, $pwd2, &$msg )
{
echo "1. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";

   if ( !strpos( $email, "@" ) )
   {
      $msg = "You must specify a valid email address!";
      return TRUE;
   }
echo "2. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";


   if ( $pwd1 != $pwd2 )
   {
      $msg = "Your two passwords did not match!";
      return TRUE;
   }

   $query = "SELECT id FROM users WHERE nickname='$nick'";
   $result = mysql_query( $query );
   $nres = mysql_num_rows( $result );
echo "3. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";

   if ( $nres != 0 )
   {
      $msg = "The nickname $nick is already in use by another user";
      return TRUE;
   }
   return FALSE;
}

function mkpasswd()
{
   srand( (double) microtime() * 1000000 );
   $unique_str = md5( rand( 0, 9999999 ) );
   return substr( $unique_str, 0, 8 );
}

function sendWelcomeMsg( $to, $nick, $pwd, $pwd1, $uid )
{
   $text = "Welcome!\n".
      "\n".
      "Your personal details\n".
      "---------------------\n".
      "Your nickname:                  $nick\n".
      "Your password to the web page:  $pwd1\n".
      "\n".
      "How to setup your phone\n".
      "-----------------------\n".
      "In your MMS settings find the option that specifies your ".
      "MMS Server (some vendors refer to it as Home Page, others ".
      " as MMSC, Message Server or Service Center). It should be ".
      " a setting under MMS where you are to type in a URL.\n\n".
      "Once you have found that setting you type in the following ".
      "URL: http://" . MYDOMAIN . "/mms/send.php?username=$pwd\n\n".
      "\n".
      "Cheers,\n".MYADMIN_NAME;


   $headers = "From: phree@" . MYDOMAIN . "\r\n".
         "Bcc: " . MYADMIN_EMAIL . "\r\n";
   $ret = mail( $to, "[phree] Welcome $nick",
           $text, $headers );
}
?>

<html>
<head>
   <title>Registration</title>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   <link rel=stylesheet type="text/css" href="style_new.css">

</head>
       <?php
echo "4. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";

      if ( isset($nick) && isset($email) )
      {
         $link = mysql_connect("localhost", "mms",MYSQL_PWD)
                   or die("Could not connect to database1");   
         mysql_select_db("mmsusers")
            or die( "Could not select databse2" );

         $error = isFaulty( $nick, $email, $pwd1, $pwd2,
                  $errmsg );
echo "5. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";


         if ( !$error )
         {
            $pwd = mkpasswd();
            $query = "INSERT INTO users VALUES " .
               "(NULL, '$nick', NOW(), NULL, NULL, ".
               "'$pwd', '$pwd1', 0, 0, 0, 0, '$fname',".
               "'$sname',".
               "'$country', '$homepage', '$email', '',".
               "0, 0, 0)";
            $result = mysql_query($query);
            print( mysql_error() );            

            sendWelcomeMsg( $email, $nick, $pwd, $pwd1,
                  mysql_insert_id() );
         

                print( "<h3>Welcome " . $nick . "!</h3>\n" );
                    print( "Your login details and info on how " .
                   "to setup your phone has been sent to".
                   " <i>" . $email . "</i>\n" );      
         }
      }
echo "6. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";


      if ( !(isset($nick) && isset($email)) || $error )
      {
         if ( $error )
         {
               print( "<b>Problems registering:</b> " .
               $errmsg . "<br><br>\n" );
         }
      ?>
      <h3 align="center">&nbsp;</h3>
   <h3>Create new user</h3>
      Thanks for choosing to register.
      This site is brought to you free of charge with no
      plans to ever charge you, the user.<br><br>
      
      Registration is quick and simple. The only required fields are
      <b><i>Nickname</i></b> and <b><i>Email address</i>
      </b>. Your email is needed only to send you your phone
      password, information on
      how to set your phone up and to check that you
      actually exist. The email will not be used for
           spamming, neither will it be sold to spammers or shown on
      the web page anywhere.<br><br>
   <form method="POST" action="create.php">
      Nickname<br>
      <input type="text" name="nick" <?php echo "7. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
if (isset($nick)) print("value=\"$nick\""); ?> <br><br>
      First name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Surname<br>
      <input type="text" name="fname" <?php echo "8. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
if (isset($fname)) print("value=\"$fname\"");?>
      
      <input type="text" name="sname" <?php echo "9. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
if (isset($sname)) print("value=\"$sname\"");?><br><br>
      Country<br>
      <input type="text" name="country" <?php echo "10. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
if (isset($country)) print("value=\"$country\"");?><br><br>
      Home page<br>
      <input type="text" name="homepage" <?php if (isset($homepage)) print("value=\"$homepage\""); else print("value=\"http://\""); ?>><br><br>       Email address<br>
      <input type="text" name="email" <?php echo "12. nick is $nick and email is $email and pwd1 is $pwd1 and pwd2 is $pwd2<br>";
if (isset($email)) print("value=\"$email\"");?><br><br>
      <input type="submit" class="submit" value="Create account">
   </form>
   <?php
      }

    ?>

   
   <?php
   $link = mysql_connect("localhost", "mms",MYSQL_PWD)
                 or die("Could not connect to database3");
   mysql_select_db("mmsusers") or die( "Could not select databse4" );
   
   ?>
   
</body>
</html>


When I go to the page and try to create an account, the page shows:

Quote:
4. nick is and email is and pwd1 is and pwd2 is
6. nick is and email is and pwd1 is and pwd2 is


Create new user
Thanks for choosing to register at phreemms.com. This site is brought to you free of charge with no plans to ever charge you, the user.

Registration is quick and simple. The only required fields are Nickname and Email address . Your email is needed only to send you your phone password, information on how to set your phone up and to check that you actually exist. The email will not be used for spamming, neither will it be sold to spammers or shown on the web page anywhere.


Followed by the input boxes for Nickname/First name/surname etc. When I enter details and then click on "Create Account", it still just reloads the page again (with all the input boxes now empty).

I believe you have the url for my site? If you want to see exactly what I mean, then it's www.myurl.com/mms/create.php
Back to top
View user's profile Send private message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 05, 2006 6:37 pm    Post subject: Reply with quote

Am I being my usual thick self here? Should I have one file that contains the form that is filled out and then another file which contains the script that the form submits to? At the moment, the file is calling itself(?):
Code:

<form method="POST" action="create.php">


Or is that ok?
Back to top
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Wed Jul 05, 2006 7:07 pm    Post subject: Reply with quote

I don't know.

Where did you get this script anyway?

I think you better just go and get it from them again.
Back to top
View user's profile Send private message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 12, 2006 2:02 pm    Post subject: Reply with quote

Just a little update that may be of some help to others in the future.

I have managed to sort out my createuser.php - but spent hours and hours fixing it - when I already thought it wasn't broken. I couldn't understand why it "used to work and now it doesn't". It started annoying me more and more because I found my old image uploader didn't work either. SO I set about finding out exactly what was going on.

I have just found out that the PHP directive register_globals went from ON to OFF in PHP 4.2.0. I moved servers a couple of months ago and am currently running on PHP 4.4.2 - I guess my old server had a version below 4.2. I have also found a fix:

In my image uploader folder, I edited my .htaccess file (if you don't have one, you can create it) and just added:
Code:

php_flag register_globals on


I then refreshed my image uploading page, tried again - and it worked first time.

Hope this helps someone else in the future.
Back to top
View user's profile Send private message
Humpa
Site Admin


Joined: 06 Nov 2005
Posts: 10258

PostPosted: Wed Jul 12, 2006 2:22 pm    Post subject: Reply with quote

Damn.
See? The fact that nick and email were empty was telling us something!

We should've used $nick = $_POST['nick']; and $email = $_POST['email'];
Since register_globals was off, it wasn't automatically doing that for you. Sad

Or we could've just put this at the begining of the file:
Code:
if(isset($_POST)) {
   if(is_array($_POST)) {
      while (list($key, $value) = each($_POST)) {
          $$key=$value;
      }
   }
}

That's why I stick this at the top of some of my scripts that I have available:
Code:
if(isset($_COOKIE)) {
   if(is_array($_COOKIE)) {
      while (list($key, $value) = each($_COOKIE)) {
          $$key=$value;
      }
   }
}
if(isset($_POST)) {
   if(is_array($_POST)) {
      while (list($key, $value) = each($_POST)) {
          $$key=$value;
      }
   }
}
if(isset($_GET)) {
   if(is_array($_GET)) {
      while (list($key, $value) = each($_GET)) {
          $$key=$value;
      }
   }
}
Back to top
View user's profile Send private message
Phree



Joined: 31 Dec 2005
Posts: 254
Location: South Coast, UK

PostPosted: Wed Jul 12, 2006 2:28 pm    Post subject: Reply with quote

Smile Yep, you got it in one! I eventually figured that by going through my file and putting $nick = $_POST['nick'] for all the inputs in my form (obviously substituting "nick" for each input name - "email"; "First name" etc - I think there's 8 of them) it would work. I still didn't know why though until I searched around earlier.

I did read that you could just edit (or add) the .htaccess file in root and put the command I just posted, but I guess if they turned it off, they did it for a reason so it's better to just use it in specific directories as and when needed?

Thanks for that piece of code as well - I'll use that in future Razz

Humpa wrote:
Damn.
See? The fact that nick and email were empty was telling us something!

We should've used $nick = $_POST['nick']; and $email = $_POST['email'];
Since register_globals was off, it wasn't automatically doing that for you. Sad

Or we could've just put this at the begining of the file:
Code:
if(isset($_POST)) {
   if(is_array($_POST)) {
      while (list($key, $value) = each($_POST)) {
          $$key=$value;
      }
   }
}

That's why I stick this at the top of some of my scripts that I have available:
Code:
if(isset($_COOKIE)) {
   if(is_array($_COOKIE)) {
      while (list($key, $value) = each($_COOKIE)) {
          $$key=$value;
      }
   }
}
if(isset($_POST)) {
   if(is_array($_POST)) {
      while (list($key, $value) = each($_POST)) {
          $$key=$value;
      }
   }
}
if(isset($_GET)) {
   if(is_array($_GET)) {
      while (list($key, $value) = each($_GET)) {
          $$key=$value;
      }
   }
}
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Help Me Humpa Forum Index -> Anything PHP All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum