Improvements To Member Registration Site Reg.php

Hence this:-

It’s not, it’s just different. I find it simpler to use.

1 Like

No, no grammatical error that I can see. Putting it another way:

“Likewise, if the query yields a set of results, the mysqli_stmt_fetch() function is used.”

For “result set”, read “set of results”.

However, that wasn’t the bit I was pointing you to, I merely included that link so you could see where I’d found the part that I quoted, that might be relevant to your problem.

I doubt anyone remembers all this stuff. All you need to be able to do is remember where to find out, or confirm what you thought was correct by just checking somewhere. Once you have an idea of what the syntax for something is, that’s when the documentation page will confirm what you thought far more quickly than some Youtube tutorial might, even presuming the YT tutorial is actually correct and up to date.

3 Likes

Though as huge PDO advocate as myself, I think that introducing a new API into this particular topic will only bring even more confusion.

Especially that if it’s exceptions being the main reason, mysqli can throw them as well.

True though this case is a bit special and traditional advice does not seem to be working.

Personally, I think using Doctrine’s Database Abstraction Layer PDO wrapper should be the default choice.

mkdir project;
cd project
composer require doctrine/dbal

// app.php
require_once 'vendor/autoload.php';

$config = new \Doctrine\DBAL\Configuration();

$connectionParams = array(
    'dbname'   => 'aoc2017',
    'user'     => 'ahundiak',
    'password' => 'secret',
    'host'     => 'localhost',
    'driver'   => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);

// Fetch a row from users
$stmt = $conn->prepare('SELECT id,username,email FROM users WHERE username = ?');
$stmt->execute(['ahundiak']);
$row = $stmt->fetch();
var_dump($row);

// UPDATE users SET email = something WHERE username = ahundiak
$conn->update('users',['email' => 'something@somewhere.com'],['username' => 'ahundiak']);

None of this binding nonsense and of course exceptions are enabled by default so sql syntax issues will be quickly picked up.

But that’s just me.

2 Likes

Thanks! I believe your code sample would become handy for me once I start on PDO.
Keep up the good work!
Throw in as many code samples as you can on many threads as you can, regardless of who opened the thread, whenever you’re free and in the mood.

Cheers!

That is encouraging.
Because, when I read through the php tutorials, I understand most of them but I seem to have problems remembering them all or remembering their parameters (how many there are and what they are). I thought everyone else is different and some-how manages to memorize them and can build any web script writing code from memory without looking at the notes. Whereas me, I would need the notes and won’t be able to code things at the top of my head. Hence, gave-up the thought of ever becoming a pro.
I just remembered. One professional programmer (probably earns $500+/day on contract jobs) mentioned to someone that he always uses notes and won’t be able to program without them.
I thought the guy is probably a very weak programmer but now I’m thinking maybe all “pros” are like that using notes all the time. And so, I shouldn’t give-up just because I can’t remember which function has how many parameters and what each parameters stand for.

So Sam, would you be able to build a web script, without your notes, by writing all the codes from memory ? How much would you manage to build likewise ?
Same question goes for others reading this.
Let me compare myself with you guys to see if there would ever be a chance to be a professional php programmer or would I remain an amateur always.

On youtube, I see the tutors writing codes from memories (they know which function does what and how many parameters they have) without needing to check any notes. That’s when I lost all hope of ever becoming like them. Ever becoming a pro one day.
Well, I guess, it comes over time eventually after many practices throughout the years.
What do you people say ?

Thanks

I’d say “Spend more time coding and working through the basics until they’re second nature, and considerably less time writing posts on forums about how bad your memory is”. Writing code, refactoring code, debugging code, optimising code and doing it on a daily basis will develop the mental equivalent of muscle memory. That’s how you remember stuff, and only have to look up ideas you’ve not seen before, or are more complex.

6 Likes

Remember everything? Goodness no!

I might remember more things while I’m using them, but with time away from the code uncertainty creeps in. I remember things I use often, eg.
for ($i; $i < $arr_count; $i++) {
but there are times when I’m not 100% sure which of these are correct eg.

str_pos($needle, $haystack) 
strpos($needle, $haystack) 
str_pos($haystack, $needle) 
strpos($haystack, $needle) 
6 Likes

Thank God! Then, I’m not alone who forgets things on php! Lol!

I often think back as to how I used to manage to code without the internet.

Maybe I should Google for a solution :slight_smile:

4 Likes

Today’s free e-book offer at Packt Press is “Learning PHP 7”. Take the opportunity to get it while you can, as the offer only lasts 24 hours. https://www.packtpub.com/packt/offers/free-learning

6 Likes

A post was split to a new topic: Views on Likes

Right this instant, my mind is on full gear trying to thinkup some wild ideas to launch some script and site that will go viral. I’ll open another thread on this and keep you guys updated (entertained enough to give me likes and feed-back) from time to time whenever anything wacko comes into my head. We live in strange times. In this day and age, the more wacko you are the more money you make and the more famous you become (singers and actors).

I was about to go ahead reading these links:

I only read one and had a question and so popped up here to ask. Finding 3 likes on John_Betong’s post made me forget all that and go off track delving into another subject. Stepped into the rabbit’s hole. And instead of coming out, I’m exploring and going deeper. Wasted my studying time. In half hr got to go out. While out, I’d be pondering at the back of my head about the viral subjects mentioned in my previous post. If anything exciting turns-up, I’m opening another thread in this forum to discuss it for feed-backs. I’ve been obsessing on how to make things go viral from feb - june. Have come-up with a few ideas which I’ll discuss in that new thread. Already discussed little bit here (dream boy/girl membership site).

Anyway, since I won’t learn much in half hr before it’s time to go out. I might aswell grab that ebook TechnoBear brought to our attention. His read my 2 posts upto here and thinking I’m polluting his forum with nonsense. Atleast, he’ll be glad that I’ve decided to download what he suggested. Turned the neg into a pos at the end. :wink:

1 Like

17 posts were split to a new topic: Download difficulties

I forgot to ask: Google for what solution ?
Maybe, people are liking your post because they expect you to find the solution and share it with them I don’t know. Beats me.

There was only a single statement and surprised you were not able to deduct the search query “how to code without using the internet”.

I did search and confirmed the internet usage can easily be abused. Hard copy has a lasting effect rather than glossing over numerous solutions.

2 Likes

If I remember correctly, I think I found-out from another forum, once upon a time, that with pdo there is no binding nonsense! If that is the case then: GOOD.
And for reminding me this: THANKS! :wink:

1 Like

Folks,

Looking at this code, is it not very clear that the $email, $account_activation_code, $userActivationState and $stmt_two been defined ?
If so, then why do I get these errors ?

Notice: Undefined variable: email in /home/user/public_html/e-id/activate_account.php on line 11
**NULL **
Notice: Undefined variable: account_activation_code in /home/user/public_html/e-id/activate_account.php on line 14
NULL

Notice: Undefined variable: userActivationState in /home/user/public_html/e-id/activate_account.php on line 23
**NULL int(0) int(0) **
Notice: Undefined variable: stmt_two in /home/user/public_html/e-id/activate_account.php on line 38
NULL

The variables have been defined like these:

	**$email = htmlspecialchars($_GET['email']);**	
	**$account_activation_code = htmlspecialchars($_GET['account_activation_code']);**
        $stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");**strong text**
**$stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
	mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);**

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 
{
	echo var_dump($email);
	$email = htmlspecialchars($_GET['email']);	
	
	echo var_dump($account_activation_code);
	$account_activation_code = htmlspecialchars($_GET['account_activation_code']);
	
	echo var_dump($stmt_one);
	$stmt_one = mysqli_prepare($conn, "SELECT usernames, accounts_activations FROM users WHERE emails = ? AND accounts_activations_codes = ?");
	
	echo var_dump($stmt_one);
	mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);
	
	echo var_dump($userActivationState);
	mysqli_stmt_bind_result($stmt_one, $username, $userActivationState);
	
	if (mysqli_stmt_execute($stmt_one) && mysqli_stmt_fetch($stmt_one))
	{
		echo var_dump($userActivationState);
		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;
		}

		echo var_dump($userActivationState);
		$userActivationState = 1;		
		
		echo var_dump($stmt_two);
		$stmt_two = mysqli_prepare($conn, "UPDATE users SET accounts_activations = ? WHERE usernames = ?");
		mysqli_stmt_bind_param($stmt_two, 'is', $userActivationState, $username);	
		
		if (mysqli_stmt_execute($stmt_two))
		{
			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 
	{
		echo "FAILURE to UPDATE db";
		exit;
	}
}

And, do you see any boolean issues on any of the following lines:

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

**mysqli_stmt_bind_param($stmt_one, 'si', $email,  $account_activation_code);**

**if (mysqli_stmt_execute($stmt_one) && mysqli_stmt_fetch($stmt_one))**

I don’t see any boolean issue on the $stmt_one variable atall.
But I get these errors:

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 40

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 42**

The config.php looks like this:

<?php

/*
ERROR HANDLING
*/
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

// session start
if(!session_start()) {
	session_start();
}

// include files
include 'conn.php';
include 'site_details.php';

// include functions
include 'functions.php';

?>
1 Like

Is there anything you do not understand with that statement?

Edit:
Unable to give the post numbers because they are not available when using the Mobile version.

1 Like

Looking at my previous post, did you not see the var_dumps floating all over the script ? And, don’t you see what error the var_dump is showing ?

1 Like