Jump to content

PHP class


razorsese

Recommended Posts

Need some help whit the following code:

 

The problem is when i try to insert into database it appears only the first letter in the name column and in the text column it appears exact letter like in the name column.

 

newArticle();
function newArticle()
{
	$article = new Article;
	$article->storeFormValues("SOMENAME","SOMETEXT");
	$article->insert();
    echo $article->id." ".$article->name." ";

}

 

class Article{

public $id = null;
public $name = null;
public $text = null;


public function __construct($data=array() )
{
	if( isset($data['id']) ) $this->id= $data['id'];
	if( isset($data['name']) ) $this->name= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['name'] );
	if( isset($data['text']) ) $this->text= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['text'] );

}

public function storeFormValues ( $params ) {

    // Store all the parameters
    $this->__construct( $params );
}
public function insert()
{
	$con = new PDO(DBN,DB_USER,DB_PASS);
	$sql = "INSERT INTO articles (name,text) VALUES (:name, :text) ";
	$st = $con->prepare($sql);
	$st->bindValue(":name", $this->name, PDO::PARAM_STR);
	$st->bindValue(":text", $this->text, PDO::PARAM_STR);
	$st->execute();
	$this->id = $con->lastInsertId();
	$con=null;
}
}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/260063-php-class/
Share on other sites

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.