Updating into databaase

hey guys!

I am trying to learn some basic php oop by mmtuts tutorials and have understood the basic when it comes to instantiating classes and selecting from the database… I can access my database now but I want to change emailactivation, which is set to 0 to 1… I am assuming that it should look something like this:


<?php

class emailactivation extends checktoken{
	

	public function emailActivation(){
	   $datas = $this->getAllUsers();
	    foreach ($datas as $data) {
	      if($data['token'] == $data['tokencheck']){
	         $sql = "SELECT id FROM user WHERE token=$data['token'] AND tokencheck =$data['tokencheck'] AND emailactivation=$data['emailactivation']";
                 $result = $this->connect()->query($sql);
	             $numRows = $result->num_rows;
	               if($numRows >0 ){
	               $sql ="UPDATE user SET emailactivation =1 AND token=''";
	               } 
	      
	   }
	      
	   }
	}

}

But I got the following errors:

Parse error: syntax error, unexpected ‘’ (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\mmtuts\includes\emailactivation.php on line 10

For starters you need to use prepared statements. Never ever put variables in your query.

I’ve a suspicion that you need to enclose the variables in { } braces inside that string to stop this being a problem. But if you convert to prepared statements instead, that won’t matter because it will be handled for you.

I also think this query

 $sql ="UPDATE user SET emailactivation =1 AND token=''";

is probably not what you want to do. For a start, you need to specify which id you update.

1 Like

I agree. I believe it’s the extra curly brace. I know that not having enough curly brace will give you end of file error. Though I haven’t tried it with too many curly braces yet.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.