Jump to content

Update Table Using Prepared Statements Issue


dflynn

Recommended Posts

Hi there,

I'm new to the forums, not completely new to PHP though.

Only recently have I started to play with Prepared Statements, so bare with me if my questions ound really stupid. I started learnign Prepared Statements through a Login script tutorial on Nettuts, so that's how I've been laying out my code.

 

Anyway,

I have three files. activate.php, activate_class.php and mysql.php.

 

in activate.php I have the following:

 

<?php
session_start();
require_once 'classes/activate.php';
$activate = new Activate();

if($_POST && $user_handle !== "" && !empty($_GET['uid'])) {
 $return = $activate->activate_User($user_handle, $_GET['uid']);
}

...

 

uid is passed through the url. a different script I'm going to ask about later ensures the uid exists in the database and then returns the user's handle to be used on the page.

 

So when the user sees the "activate your account" message and clicks activate that snippet is activated and leads to this, in activate_class.php:

 


function activate_User($un, $pwd) {
	$mysql = new my_sql();
	$activate = $mysql->activate_Uid($un, $pwd, 1);
	if($activate) {
		header("location: welcome.php");
	} else return "failed to activate"; 
} 

 

and in the mysql.php file:

 

function activate_Uid($un, $pwd, $verified) {
	$query = "UPDATE members 
			SET user_verified = ? 
			WHERE user_handle = ? AND user_password = ? 
			LIMIT 1";

	if($stmt = $this->conn->prepare($query)) {
		$stmt->bind_param('iss',$verified, $un, $pwd);
		$stmt->execute();

		if($stmt->fetch()) {
			$stmt->close();
			return true;
		}
	}		
}

 

 

Everything works fine and the database inserts the 1 into user_verified. However when the

if($activate) {
		header("location: welcome.php");
	} else return "failed to activate"; 
} 

runs, it seems as though the Update function is returning false because it doesn't redirect. Instead it shows the "failed to activate" text.

 

 

Any ideas why it would be returning false but still executing?

 

Thanks. I think this might fix a few other errors I am having.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.