How to insert record with MySQL without using interactive tool?
Rate Topic:

How do you insert a record into DB table without using CRUD from the interactive tool?
I cannot insert a new record into DB even when i try to copy from the blog example....
Please help me.... I'm a newbie to yii...

How do you insert a record into DB table without using CRUD from the interactive tool?
I cannot insert a new record into DB even when i try to copy from the blog example....
Please help me.... I'm a newbie to yii...

Hi Alex,
Thnks for the reply, but I still can't insert a new record in MySQL database.
I am able to view the results but no insertion of record have take place.
The following are my codes, please take a look whether if I understand you correctly.

class MessageController extends CController
{
private $_model;
public function actionShow()
{
// create a new instance of MessageForm model
$message=new MessageForm;
/*
* check to see if the MessageForm fields were filled in
*
* If they were, then print out the message and author
* with the show render - based on what the user inputted
*
* If not, then print out the default hellow world and
* default author with the show render.
*/
if(isset($message->message))
$this->render('show',array('message'=>$message));
else
{
$message->message = "Hello World";
$message->author = "Default Author";
$message->phoneNumber = "123456";
$message->cars= "Dropdown List";
$this->render('show',array('message'=>$message));
}
}
public function actionEdit()
{
// create a new instance of MessageForm model
$message=new MessageForm;
/*Your method here*/
$messagesave = new message($_POST['MessageForm']);
$messagesave->save();
/*
* check to see if All the fileds are filled in on the form
* if so proceed to assign the values to the variables in
* the message model (author and message)
*
* If they validate (no errors) then render the show page
* with the new data values
*
* If there's errors, return to the edit form showing the
* errors
*
* Finally if the form wasn't set then we render the edit
* page so that the user can input field values.
*/
if(isset($_POST['MessageForm']))
{
$message->attributes=$_POST['MessageForm'];
//$message->save();
if($message->validate())
$this->render('show',array('message'=>$message)
);
else
$this->render('edit', array('message'=>$message));
}
else
$this->render('edit', array('message'=>$message));
}
public function actionIndex()
{
$this->render('index', array(
'Users' => Users::model()->findAll(),
//'Products' => Product::model()->findAll(),
//'Sms' => Sms::model()->findAll(),
//Product Table's relationship with Brand Table is being preloaded.
'Products' => Product::model()->with(array('brand'))->findAll(),
));
}
}