Improvements To Member Registration Site Reg.php

How does this link:

http://www.localhost/id/activate_account_edited.php?email=EDITED@gmail.com&hash=$2y$10$AtFLJ6DuE/rq.AXFq3zFfOd2r.NIi7LeT4/dXHRn8dF

relate to this code here:

$confirmed_email = trim($_GET["email"]);
$account_activation_code = trim($_GET["account_activation_code"]);

If the code you posted in post #160 is the one you’re having trouble with, compare those two snippets and see what the issue is. It’s a bit hard to tell because your link is to “activate_account_edited.php”, but you talk about “account_activation.php”, so I might be looking at the wrong code. But the specific issue I am looking at is still there in your volunteers code in post #149.

What you need to do asap is get back to the drawing board and begin learning php - and that means studying php documentation (yes!) and other tutorials and experimenting on your own. You first need to begin to understand code by yourself and stop gluing random pieces from other people expecting it will all work magically.

Then, when you have a question here it should be concise and very specific to one problem only and you should show a very short piece of code, a few lines at best, that you have a problem with. Hardly anyone has time to wade through all the code you are posting here, especially when it’s apparent you aren’t learning by yourself what you should be learning.

You would have made a lot more progress if the time posting on these forums you had spent learning the language. These forums can be very helpful but only for those who are willing to do their (home)work, too.

5 Likes

Most people when they learn to program, start with a “Hello world” program and work up. You seem to have skipped that step - and several dozens more - and tried to write a complex suite of programs that most people wouldn’t attempt till they were competent in the language.

1 Like

@uniqueideaman Different people learn in different ways. You seem to have started with a bottom up approach in which you trying to learn the basics and build up from there. It is quite a popular approach but has it’s problems. In particular, for account registrations, there are literally thousands of “how to” articles out there 99% of which are outdated and/or crap. How to pick the right approach is not easy.

You might consider trying more of a top down approach. Basically, start with a framework that gives you a working application and then learn from there. The framework gives you plenty of code to look at and, as long as it is reasonably modern, will help guide you along to writing decent code.

I myself like Symfony: https://symfony.com/ I suspect you may struggle a bit when it comes to installing and using composer (the php package manager) but if you get past that then I think you might be surprised at what you can do with it.

Just a thought especially if you find yourself channeling your inner Trump. I mean, who knew that web programming could be so hard.

Ofcourse, I care for my script. Otherwise, I would have not have bothered displaying my script in this thread. I’m not gonna bother arguing with you and get banned.
One thing I will say worthy you have given me is that Jackie Chan pic! Lol!
I’m gonna test my script on my website now. Last time tested on localhost.
Don’t bother replying.

droopsnoot,

Sorry, but I don’t understand your first question.
I loaded that url in my browser:

**http://www.localhost/id/activate_account_edited.php?email=EDITED@gmail.com&hash=$2y$10$AtFLJ6DuE/rq.AXFq3zFfOd2r.NIi7LeT4/dXHRn8dF**

I changed my email in this thread to “EDITED” to conceal my email so bots/spiders don;t harvest it that crawl this thread.
account_activation.php is the original file name. The one that had not the BINDINGS. My original code. account_activation_edited.php is the code the editor created out of my original code. The post#160 mentions the latter code. Once the latter code is found to be working then I will replace the orrginal code with it. meaning, it will be renamed account_activation.php.

I tried testing the latter code now by uploading all the required files to my site and registering an account to see if the account activation link gets emailed or not and if it works or not after it gets click. Does it activate the account or not. But the register.php is showing an error which I’ mentioning in my next post.

Thanks

I did start with the “Hello World!” back in sep 2015. Nothing much to learn here.

echo “Hello World!”;

Read through the whole tizag.net basic tutorial in 2wks. Then gave 1.5yrs of gap.
Then started downloading youtube tutorials and grabbed snippets (which I understood). I still got them. Basic codes related to Php dealing with “MySql”. Such as:

  • Create DB
  • Create Tbl
  • Insert into Tbl
  • Delete from Tbl
  • Update Row.
  • Insert simultaneously into more than one column.
  • etc.

*** Member-Reg-Login site**
*** Searchengine & Web Crawler**

  • Friend System (Social Network)
  • Follow System (Social Network)

And so, I do have snippets and I do understand them. And so, I don’t have any issues with them. They work. I don’t get any errors. And so, I don’t bother the forums regarding them. I do understand each lines of these snippets or small codes. But, I have not memorized them. Can’t write them at the top of my head, without checking the notes first.
I have now moved-on to the member-reg-login site project. While I was dealing with it, I came across code issues as a lot of the youtube tutorials were using deprecated stuffs. Hence, the need to create threads in the forums to get some help to learn what is old stuff and what is new stuff, etc. Anyway, in the middle of all these error issues, I got put-off a little from that project and put it aside for a while and found interest to learn web scraping and so moved-on to learning cURL a little. I thought best take a break from the member-reg-login site project to refresh my mind but why spend days taking break learning nothing and so best I try another subject & project.
I then, launched the web proxy (both php & cURL) project. The aim was to build one that logs into mysql all proxified pages’ urls. Many programmers in many forums told me it is not possible to log proxified pages. I, the newbie, amateur upstart, proved every single one of them pros wrong. :wink:
Anyway, I then moved onto building my own web proxy and encountered problems and faced some problems when trying to add feature to log the proxified pages’ urls. Ok, I managed to add the logging code onto MiniProxy (3rd party proxy) and it logs proxified pages’ urls onto my mysql but when I tried building my own web proxy from scratch and add the logging code, I started encountering problem after problem and got puzzled why it works on a 3rd party script but not my own. I know, I am doing something wrong. Anyway, it’s a good thing that I faced these problems because the members here made a lot of suggestions such as use array to feed the words that I need replacing as coding would be simpler and shorter, etc. and a whole lot of other stuffs regarding preg_replace and str_replace. I never would have gained work experience on those subjects had I not opened the threads. And, I never would have opened the threads had I not encountered the problems. And, I never would have encountered the problems had I not embarked on these projects. And so, all this ducking & diving and facing near drownings here and there in the pools and ponds and lakes and rivers have been a good experience for me. Making me stronger in coding and mentally to go on and not quit php. Else, I would have quit php half a yr ago when I was going through php.net. All that messy code put me off. It’s the love for these projects (I embarked on) is what keeps me going and hanging onto php and delaying approaching the gate towards Python. I know Python is simpler and by now I would have learnt it.
But, I want to finish php first. I’ve come this far. I’ve managed to prove some php pros wrong by adding a logger onto proxified pages, I’ve nearly finished my member-reg-login site. I’ve nearly finished building my own web broxy from scratch. Ok, I admit. Half finished it. So, why should I quit now or go back to the drawing board ? Yes, I will go back to learning the basics now and then. cpradio suggested codeacademy.com and that is a good exercise site. I like it. Will continue learning from there because they test you on each chapter and all the trial and error makes me remember what I learn while the other sites don’t test you and I easily forget what I learn when I move onto a new chapter. Other sites like tutorialspoint.com, tizag.net, etc.

Anyway, so I just updated you all what I am upto. I hope I don’t have to repeat all this again as I’ve repeated it a few times these last few mnths and it is getting boring.
So do remember. My 2 current projects now are to build my own member-reg-login site (and that is 95% finished once I get rid of all these minor errors) and build my own web proxy (that is nearly half finished).
About 12hrs ago, downloaded youtube tutorial on how to build a basic meta engine. Gonna open another project on this very soon. It is a small project, anyway. And so, I don’t think I will encounter any problems (unless the tutor’s code was full of deprecated stuffs).
I think from the video, I will learn and gain work experience on basic web scraping. How to scrape parts of the page. I can use that experience to build my own web crawler one day. Right now, with cURL and php, I can manage to fetch full webpages (full scrape of the page) but not parts of it such as keywords, meta tags, etc. And so, I reckon this video will teach me what I lack. And then one day, I will build many mini tools related to web scraping and open it to the public to use the tools to grab this or that data from sites. :slight_smile:

PS - Again. I repeat: I will not give-up. Won’t quit the member-reg-login site and web proxy projects. Will struggle and complete. I am enthusiastic. Wait, watch and see where my enthusiasm leads me. Wait and see what kind of scripts I derive from them. I am someone who can always come-up with improvements to an old idea or come-up with my own unique ideas. Which when heard about, you will wonder: Why did I not think of all this before ? :wink:

PPS - Whenever I have a project in mind. I never go around forums asking for codes here and there where I never made any inputs and all the codes came from all the forums. No. I first, download the codes from youtube. Then try understanding them. Testing them. When I don’t understand a code or encounter an error in the testing, I then open threads in the forums. I only prowl 2 forums now. This one is my best. Not flattering anyone here. It is the truth. Best in getting responses and best in getting well mannered answers without getting accused or abused. (Let’s forget Colshrapnel’s recent accusations here about me getting all my codes from talking into members building my scripts).
Here is proof that I don’t get all my codes from forum members by “talking them into building my whole scripts” like accused …
Look at the images. How many youtube php tutorial videos you see downloaded ? Count and see. After all this, do I need to “talk any forum member to build my whole script” for me ?
Yes, I do ask for code samples now and then but that are snippets and not the whole script. Only ask when I’ve struggled for a wk or 2 on the topic/feature. I only ask when I come to dead-ends in finding code solutions and the hints (solutions) I get from others are way beyond my skills to understand their hints.

PS - I wanted to upload some screen shots of my computer listing all the youtube tutorials I have downloaded but I’m gonna have to upload a lot of imgs and I don’t think the mod will like that. In short, I have over a hundred vids.

Look again at the URL, and look at the variable names you pass as part of that URL. Then look at the variable names that you are extracting at the top of your PHP code in order to process the account activation. You must be able to see the difference.

1 Like

Still you don’t understand what you were asked for.

It seems you still don’t care that much for your app than for telling us how much you care.
Trust me, we don’t need your excuses. We need your effort for your own app. If you had spent 1/10 of the effort it took you to write this lengthy memoir to the actual testing of your app, you would have it fully working by now.

For now, you are taking our advises as an irritating noise. You take us as dull teachers with pointless demands.
And you need to change that attitude of yours completely. From a schoolboy to a full grown man.

A schoolboy don’t want to learn boring sciences, and doing that only when forced by a teacher. Cunningly devising every possible excuse to abstain from doing their homework. So you are doing here: “I’ll test it tomorrow”, “I tried it and it didn’t work!”, “I’ll test it on a server”.

COME ON! That’s ridiculous.
It’s not us who need these tests. It’s you. We are not interesting in listening to reasons why you failed and what are you going to do. It’s you who needs a working app.
A full grown man knows what he needs and does his job. On his own accord, not being constantly pushed by other people.

You’ve been told by many people to test your app. fully test.

It doesn’t mean to try it for 5 seconds and to get beck telling us it doesn’t work. It means

  • to look at the code.
  • to list all the possible scenarios handled in the code
  • to decide, what should be the outcome seen by the user for all these scenarios.
  • to test every single scenario and to see whether the actual result is the same as expected.
  • to think why the result is different
  • to try fixing the code by yourself.

and only after completing all the steps above you are more than welcome to come here and ask specific questions.

Yes, it could be hard for you at first. So we offer you help. After completing each step you come here and write the results. But beware! DON’T keep it your usual way, doing it formally and make us do 90% of the job. I HOPE you will be able to solve such problems like making your variable names consistent or writing the same code twice. I am sure you’re able spot such a silly mistakes yourself. If you only take care. So grow up.

1 Like

OFFTOPIC
Droopsnoot my friend, I was going to reply to you 12 nights ago (and so have not been ignoring you or anyone here) but 2 things prevented me. Techono Bear banned me for 10 days.
One of the other problem was that, I have not been well lately and therefore did not notice I have been re-instated 2 days ago.
Nearly got paralised 6 nights ago (thur 13th July 17 eve). Ergonomics problem. Don’t sit too long at your desk infront of your computers and do buy an ergonomic chair unless you want to suffer back pains (nerve systems) where the pain passes onto the legs (after you take pain killers for your back) and then don’t cure from there and swell your ankle. I limp now. But, not using walking sticks. Had to go to hospital 2 days. First medication numbed my leg to cure the pain and made things worst. I lost control of the leg and used to walk wobbly.
Anyway, a little better now as 2nd doc changed that prescription and my leg is in my control now. Have to exercise my toes and knee regular. I thought I was gonna get paralized like Christopher Reeve and then die. 2nd doc referred me to physiotherapy and warned me that I am showing symptoms (where the problem starts and ends-up being paralized from waste downwards). High chance I will never walk again!!! (Unless ofcourse, I start exercising my toes & feet regular to kick-out of this nerve system problem so it does not get any worst)
Pain was like hell and kept shifting from limb to limb wherever the weight of the body got concentrated. Couldn’t even sleep. :worried:
That would have been the end of my php ventures. But, I’m destined to complete them to save the world from poverty. :slight_smile:
So, before I start the day here, after 12 days of absence, I stress: Don’t sit too long at the same posture. Everyone.You will regret it. I used to stay up all night in front of my computers (day & night 12-15hrs per day for a nearly a dacade) and that’s when the problems started more than a dacade ago. About 3yrs back, gp said I have to walk a few miles each day (get the walking exercise) or find myself chair ridden at 50.
Ok, Now, you all know, I have not been ignoring you. Getting back on topic.

ON TOPIC:

http://www.localhost/id/activate_account_edited.php?email=EDITED@gmail.com&**hash=$2y$10$AtFLJ6DuE/rq.AXFq3zFfOd2r.NIi7LeT4/dXHRn8dF**

I have highlighted the part where you hinted (12 days ago) the problem was. I fixed it 12 days ago).
Anyway, I am going back to work. Gonna get this forum busy and all up and running like mad.

Thanks! :slight_smile:

PS - I wonder if anyone here would have missed me if I … (RIP).

Ok. I’ve got back to learning the basics in after 2wks on php.
Been revising a little to jog my memory.
I did learn about PREPARED STATEMENTS but as you know, when you first learn things it is RAW in memory and you forget things. Going through it many days slowly sinks in. My weakness is PREPARED STATEMENTS and so was doing my usual mental exercise on it. And, I have one question.

Right now, was reading:
https://www.tutorialrepublic.com/php-tutorial/php-mysql-prepared-statements.php

The following code is what they showed as an example. It had comments. But, I added my own too in bold black.
I’m just adding my own comments to show you people how much I understood and where I have the question.
Do you mind answering my question by reading the comments ?

Thanks! :wink:

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "root", "", "demo");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 
// Prepare an insert statement
$sql = "INSERT INTO persons (first_name, last_name, email) VALUES (?, ?, ?)";
 
if($stmt = mysqli_prepare($link, $sql)){
    // Bind variables to the prepared statement as parameters
/*
ARE WE SURE THAT, THE ABOVE LINE IN BOLD ONLY BINDS VARIABLES TO THE PREPARED STATEMENTS ? BECAUSE IT SEEMS TO ME THE ABOVE LINE ALSO CHECKS IF DATA SUBMISSION TO DB WAS A SUCCESS OR NOT. MY QUESTION IS, WHY IS IT CHECKING FOR THIS AT THIS POINT WHEN THE SUBMISSION HAS NOT BEEN MADE YET ?
*/
    mysqli_stmt_bind_param($stmt, "sss", $first_name, $last_name, $email);
    
    // Set parameters
    $first_name = $_REQUEST['first_name'];
    $last_name = $_REQUEST['last_name'];
    $email = $_REQUEST['email'];
    
    // Attempt to execute the prepared statement
/* 
OK. I CAN UNDERSTAND WHY AT THIS POINT THE SCRIPT IS CHECKING WHETHER THE DATA SUBISSION TO DB WAS SUCCESSFUL OR NOT SINCE THE DATA HAS BEEN SUBMITTED NOW.
MY QUESTION IS, WHY CHECKING FOR THE SUBMISSION TWICE ? WHY DID IT CHECK EARLIER FOR NOTHING ?
*/
    if(mysqli_stmt_execute($stmt)){
        echo "Records inserted successfully.";
    } else{
        echo "ERROR: Could not execute query: $sql. " . mysqli_error($link);
    }
} else{
    echo "ERROR: Could not prepare query: $sql. " . mysqli_error($link);
}
 
// Close statement
mysqli_stmt_close($stmt);
 
// Close connection
mysqli_close($link);
?>
 

In my opinion, the line at 14 is unnecessary!
Highlighted below the unnecessary part.

if($stmt = mysqli_prepare($link,** $sql**)){

What is your opinion ?

The comment is describing the following line, not the one above. I thought it would be obvious to most people that the line with mysqli_stmt_bind_param is the line that binds parameters.

I know the comment comes prior to the code.

I thought the $sql here means it’s checking if the data submission was successful or not.

LINE 14


if($stmt = mysqli_prepare($link, $sql)){

The $link checks if the connection was successful or not. And so what does the $sql check here then ?

I have a feeling Technobear will reply to me like this:

“If the $sql in line 14 means it is checking whether the submission was successful or not and if line 24 does the same too then do they seem the same to you ?”

LINE 24


if(mysqli_stmt_execute($stmt)){

FULL CONTExT OF LINE 24


if(mysqli_stmt_execute($stmt)){
        echo "Records inserted successfully.";
    } else{
        echo "ERROR: Could not execute query: $sql. " . mysqli_error($link);
    }
} else{
    echo "ERROR: Could not prepare query: $sql. " . mysqli_error($link);

Let us see what he and you say. Best not to put words in his mouth. Just mentioned this to prove that I am aware that the 2 lines are not identical so he does not bother getting frustrated to bring this to my attention.

If you want to know what the different mysqli statements do, may I suggest you first read and try to comprehend what the PHP manual has to say about them?

http://php.net/manual/en/book.mysqli.php

1 Like

There is a billion link there. You don’t expect me to read all of them do you ?
Which ones are relevant ?

Of course not. All or none, makes no difference to me :wink:

The relevant ones are the ones about the statements you use in your code.

6 Likes

Ok. I see one:
http://php.net/manual/en/mysqli.quickstart.prepared-statements.php

Anyway, welcome aboard in helping me in learning php and helping me in my projects that are geared towards helping me learn php (and other newbies too!). He! He!

Cheers!

Guys,

Looking at this line, can you tell me if mysqli_stmt_bind_param() has in it’s 1st parameter a statement or a boolean ?

Line 22

**if (mysqli_stmt_execute($stmt)){**

Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/user/public_html/e-id/activate_account.php on line 22

And, looking at this line, can you tell me if there is a mysqli_stmt_execute() atall!
To me, there is no mysqli_stmt_execute() atall!
And so, there is no question of it having in it’s 1st parameter a statement or a boolean!

I use Notepad++.

Line 23

**echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";**

And so, why do I get this error ?
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/user/public_html/e-id/activate_account.php on line 23

Here is the full script:

account_activation.php

<?php

include 'config.php';

if (!isset($_GET["email"], $_GET["account_activation_code"]) === true){
    $_SESSION['error'] = "Invalid Email Address! Invalid Account Activation Link! This email is not registered! Try registering an account if you do not already have one! <a href=\"register.php\">Register here!</a>";
    exit();
} else {
    $stmt = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");
    mysqli_stmt_bind_param($stmt, 'si', $_GET["email"],  $_GET["account_activation_code"]);
    mysqli_stmt_bind_result($stmt, $username, $userActivationState);

    if (mysqli_stmt_execute($stmt) && mysqli_stmt_fetch($stmt)){
        if ($userActivationState != 0){
            echo "Since your account is already activated, why are you trying to activate it again ? Do not do that again and just login from <a href=\"login.php\">this webpage</a> next time! Make a note of that webpage, ok ?";
            exit;
        }

        $userActivationState = 1;
        $stmt = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
        mysqli_stmt_bind_param($stmt, 'is', $userActivationState, $username);
        if (mysqli_stmt_execute($stmt)){
            echo "<h3 style='text-align:center'>Thank you for your confirming your email and activating your account.<br /> Redirecting you to the login page ...</h3>";

            $_SESSION["user"] = $username;

            header("location:home.php");
            exit;
        }
    } else {
        $email = htmlspecialchars($_GET['email']);
        $code = htmlspecialchars($_GET['account_activation_code']);
        echo "Invalid Email Address or Invalid Account Activation Link! This Email $email was not pending registration with this Account Activation Code $code!
        Try registering an account if you have not already done so! <a href=\"register.php\">Register here!</a>";
        exit;
    }
}
}

It is whatever the value of $stmt is, which cannot be known from an isolated line of code where we don’t see where $stmt is being defined.

In the later code we see $stmt defined twice.

$stmt = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");

and

$stmt = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");

If the error says it’s a boolean, it is a boolean, that is a value of either true or false.
If the result of those lines is a boolean (false) then there has been an error when running that line.

I think you are counting the lines incorrectly. That error message is about mysqli_stmt_bind_param, which doesn’t occur in the line you have quoted. Likewise the second error message doesn’t match the code you’ve shown.

I’m not sure how you’re checking the line numbers, but there’s a mismatch somewhere.