Extract database value

Hi,

I have a very simple issue.

  • User enters email , the clicks button

  • Using Ajax, I check if the email exists or not in db, if it does, I retrieve corresponding username from the database.

I am ABLE to compare the user input against database but UNABLE to retrieve the username corresponding to email(the bold part below).

[i]My controller code is

if(isset($_POST[‘index’]))

{


			


	        $criteria=new CDbCriteria;


		$criteria->select='email';  // only select the 'title' column


		$criteria->condition='email=:postID';


		$criteria->params=array(':postID'=>$_POST['index']);


		$model2=User::model()->find($criteria);

[/i]

		[u][b]if ($model2!=NULL)


		


		{


		        $username=$model2->username;


			  


			 $this->renderPartial('_task', array('username'=>$username));


		


		}[/b][/u]


	}

_task code

<li>

<div class="tasks">

<?php echo $username; ?>

</div>

</li>

}

It seems like you are not retrieving the "username" from the DB

$criteria->select=‘email, username’; // only select the ‘title’ column

$criteria->condition=‘email=:postID’;

$criteria->select you were only selecting email, username was not being retrieved.

This should work now.

I did this. Its WORKING. Thanks!!!

Glad to hear… ;)