Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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