Jump to content

razorsese

Members
  • Posts

    66
  • Joined

  • Last visited

Everything posted by razorsese

  1. How I can increment a value into database ?! When I try whit my code it's replacing the data from mysql database not summing up $conn = new PDO( DBN, DB_USER, DB_PASS ); $sql = "UPDATE articles SET rating =:rating+1, totalv=:totalv+1 WHERE id = :id"; $st = $conn->prepare ( $sql ); $st->bindValue( ":rating", $this->rating, PDO::PARAM_INT ); $st->bindValue( ":id", $this->id, PDO::PARAM_INT ); $st->bindValue( ":totalv", $this->totalv, PDO::PARAM_INT ); $st->execute(); $conn = null;
  2. Well I fixed it by pass in function addcomment($pass) a variable
  3. Tried that but now the problem appear before i submit something right on viewArticle.php page
  4. So i got the following problem: i got some pages : index.php , comment.php, viewArticle.php When i try to submit something from comment.php appear a error "Undefined variable:result" The var result is defined in index.php When i click on one article from the list the function viewArticle() is requiring viewArticle.php and the function addcomment() is requiring comment.php The addcomment function() is in viewArticle function() I can't figure out what's wrong but I guess have something to do whit the form action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" index.php code <?php include('config.php'); $action = isset($_GET['action'])?$_GET['action']:""; switch($action) { case 'viewArticle':viewArticle();break; default:homepage(); } function homepage() { $result = array(); $data = Article::getlist(1); $result['article']=$data['result']; $result['total']=$data['totalrows']; require('homepage.php'); } function viewArticle() { if( !isset($_GET['articleid']) )homepage(); $result = array(); $result['article'] = Article::getbyid((int)$_GET['articleid']); $result['name'] = $result['article']->name; addcomment(); require('viewArticle.php'); } function addcomment() { if(isset ($_POST['submit'] )) { $comment = new Comment; $set = array(); $set['usern']="HJhj"; $set['com']="aca wqeq"; $set['page']=7; $comment->storeFormValues($set); $comment->insertc(); } else require('comment.php'); } ?> viewArticle.php code <center> <h1> <?php echo $result['article']->text ?> </h1> comment.php code: <form method='post' action="index.php?action=viewArticle&articleid=<?php echo $result['article']->id?>" > <input type="hidden" name="id" value="56"/> <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="56" /> <input type="submit" name="submit" value="submit" /> </form>
  5. 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
  6. 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; } } ?>
  7. 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; } }
  8. aaaaaaaaaaaaaaaaaaaaarGHHHHHHHHHHHHH!!!!1 thx!
  9. I can't figure what's wrong whit the following code: I get the following error: Undefined property: PDOStatement::$execute on line 26 public function getbyid($id) { $con = new PDO(DBN,DB_USER,DB_PASS); $sql = "SELECT * FROM articles WHERE id=:id"; $st = $con->prepare($sql); $st->bindValue(":id" , $id, PDO::PARAM_INT); $st->execute; $row=$st->fetch(); $con=null; if( $row ) return new Article ($row); }
  10. Yep.I saw that before entering the forum
  11. After I inspected whit FireBug in console log the values appear correctly but for some reason don't appear in the html page
  12. Well when i submit a comment in the html page the PHP code insert correctly in the database but fails at SELECT * FROM And also if i manually assign a value to $threadid right before the second query for example 2 in the html page the value from database appear correctly: Without assigned value (Not displaying correctly): http://s17.postimage.org/c1ldbk6gf/example1.png With assigned value(Displaying correctly):http://s17.postimage.org/8knwmbwrz/example2.png
  13. Still the same problem and mysql_error()) don't report anything
  14. The problem is whit the var $threadid . It dosent work here(it dosen't display the data from database): $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; But if I assign a value before the that code the html page show correctly. include("config.php"); $name = $_POST['name']; $comment = $_POST['comment']; $threadid = $_POST['threadid']; if($name & $comment) { $dbh="INSERT INTO comments (name,comment,threadid) VALUES ('$name','$comment','$threadid') "; mysql_query($dbh); } $dbh = "SELECT *FROM comments WHERE threadid = '".$threadid."' "; $req = mysql_query($dbh); while($row=mysql_fetch_array($req)) { echo "<li>"; echo "<br>"."<b>".$row['name']."</b></br>"."<br>".$row['comment']."</br>"; echo "</li>"; } $('.submit').click(function(){ location.reload(); var name = $("#name").val(); var comment = $("#comment").val(); var threadid = $("#v").val(); var dat = 'name='+name+'&comment='+comment+'&threadid='+threadid; $.ajax({ type:"post", url:"comment.php", data:dat, success:function(){ console.log("dat"); } }); return false; });
  15. $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json', success: function(response) { alert(response); } }); Still appear null in 'voting.php' page but the alert is showing the right value.
  16. So i'm sending id value trough post in json format. When i open Firebug it returns the correct value but in php it's keep returning null. $('.stars').bind('click', function() { var star = this; var data = {'q' : $(star).attr('id') }; $.ajax({ type:'post', url:"voting.php", data:data, dataType:'json' }); return false; }); <?php $q=$_POST['q']; echo json_encode($q); ?>
×
×
  • 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.