razorsese Posted March 31, 2012 Share Posted March 31, 2012 Ok .I tried to look for the problem for about 1 hour but I can't see what's wrong whit the following code: In firebug the post values appear correctly like so:id=116&usern=asdawe&com=qweqw&page=116&submit=submit and the inserc() function works correctly because i tried it whit a array of data created by my; <?php if(isset($_POST['submit'])) { $comment = new comment; $comment->storeform($_POST); $comment->insertc(); } ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <input type="hidden" name="id" value="<?php echo $result['article']->id ?>"/> <ul> <li> <input type="text" name="usern" id="usern" /> </li> <li> <textarea name="com" id="com" COLS=40 ROWS=6></textarea> </li> <input type="hidden" name="page" value="<?php echo $result['article']->id ?>" /> <input type="submit" name="submit" value="submit" /> </ul> </form> <?php class comment{ public $id = null; public $usern = null; public $com = null; public $page = null; public function __construct($data=array() ) { if( isset($data['id']) ) $this->id= (int)$data['id']; if( isset($data['usern']) ) $this->usern= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['usern'] ); if( isset($data['com']) ) $this->com= preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-zA-Z0-9()]/", "", $data['com'] ); if( isset($data['page']) ) $this->page= (int)$data['page']; } public function storeform ( $params ) { // Store all the parameters $this->__construct( $params ); } public function insertc() { $con = new PDO(DBN,DB_USER,DB_PASS); $sql = "INSERT INTO comments (usern,com,page) VALUES (:usern,:com,:page)"; $st =$con->prepare($sql); $st->bindValue( ":usern", $this->usern, PDO::PARAM_STR ); $st->bindValue( ":com", $this->com, PDO::PARAM_STR ); $st->bindValue( ":page", $this->page, PDO::PARAM_INT ); $st->execute(); $this->id = $con->lastInsertId(); $con = null; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/260108-php-form-post-and-database-insert/ Share on other sites More sharing options...
smerny Posted April 1, 2012 Share Posted April 1, 2012 the reason no one has responded yet is probably because you never said what is going wrong. so rather than us just looking to see why something is going wrong, we have to guess and look for what might be going on wrong and what might work to finish it. Quote Link to comment https://forums.phpfreaks.com/topic/260108-php-form-post-and-database-insert/#findComment-1333141 Share on other sites More sharing options...
Muddy_Funster Posted April 1, 2012 Share Posted April 1, 2012 erm.... is your question? Quote Link to comment https://forums.phpfreaks.com/topic/260108-php-form-post-and-database-insert/#findComment-1333142 Share on other sites More sharing options...
razorsese Posted April 1, 2012 Author Share Posted April 1, 2012 My problem is when i submit some data the database isn't updating and is redirecting to the index.php page The structure is like so index.php require("viewarticle") viewarticle.php require("comment.php") which is the first code above Quote Link to comment https://forums.phpfreaks.com/topic/260108-php-form-post-and-database-insert/#findComment-1333236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.