php - Data not being entered into database at all? -


i have strange issue project working on. code runs, without error, values aren't entered database insert statement.

the code follows:

pipe.php (the file calling query):

#!/usr/bin/php <?php  require_once 'includes/init.php';  init::initialise();  $email = file_get_contents('php://stdin'); $db = new db($config['db']);  $mail = new mail($email);  $emailbody = $mail->getplainbody(); $emailsubject = $mail->getsubject(); $from = $mail->getheader("from"); $to = $mail->getto();  if ($id = util::getid($emailsubject)) {      $ticket = $db->query_assoc("select * tickets ticket_id=$id");      if (in_array($from, $config['staff_emails']))     {         //staff reply          $tickets = $ticket['content'].="<ticketsep>$emailbody";          $db->query("update tickets set content=$tickets ticket_id=$id");          mail($ticket['email'], "[$id] member of staff replied ticket: ".$ticket['subject'], $emailbody);     }     else     {         //client reply          $tickets = $ticket['content'].="<ticketsep>$emailbody";          $db->query("update tickets set content=$tickets ticket_id=$id");          foreach ($config['staff_emails'] $email)         {             mail($email, "[$id] [client response] $emailsubject", $emailbody);         }     }  } else {         {         $id = rand(1000000, 9999999);          if (!util::in_array_r($id, $db->query_all('select * tickets')))         {             break;         }     }     while (true);      $db->query("insert tickets values \($id, $emailsubject, $emailbody, $from\)");       foreach ($config['staff_emails'] $email)     {         mail($email, "[$id] [new ticket] $emailsubject", $emailbody);     } } ?> 

this line doesn't work, no data inserted: $db->query("insert tickets values \($id, $emailsubject, $emailbody, $from\)");. can't test other insert query, there's no data ;)

the db class looks (no comments on code style please, of works :p):

<?php  class db {      private $link;      /**      * constructor.      * @param array $dbconfig array of database configuration:      *      * host - database host      * user - database user      * password - database user password      * dbname - database name      * port - database server port      */     public function __construct(array $dbconfig)     {         $this->link = mysqli_connect($dbconfig['host'], $dbconfig['user'], $dbconfig['password'], $dbconfig['dbname'], $dbconfig['port']);          if (!$this->link)         {             throw new databaseexception("unable connect database, please check settings in config.php file!");         }      }      /**      * query database      * @param string $query sql query run      * @return mysqli_result      */     public function query($query)     {         $result = mysqli_query($this->link, $query);         $this->checkerror();         return $result;     }      /**      * gets first row of query.      * @param string $query sql query      * @return array enumeriated array of first row contents.      */     public function query_first($query)     {         $result = mysqli_fetch_row($this->query($query));         $this->checkerror();         return $result;     }      /**      * gets first row of query associative array      * @param string $query sql query      * @return array associative array of row. column name->column value.      */     public function query_assoc($query)     {         $result = mysqli_fetch_assoc($this->query($query));         $this->checkerror();         return $result;     }      /**      * gets results array.      * @param unknown $query      * @param string $resulttype      * @return array      */     public function query_all($query)     {          if (function_exists('mysqli_fetch_all')) # compatibility layer php < 5.3                 $res = mysqli_fetch_all($this->query($query));             else                 ($res = array(); $tmp = mysqli_fetch_array($this->query($query));) $res[] = $tmp;              return $res;     }      public function checkerror()     {         if ($this->error != '')         {             throw new databaseexception("database error(s) occured: $this->error");         }     }      /**      * instance of object.      * @return db      */     public static function _getinstance()     {         return $this;     }      public function __get($name)     {         switch ($name) {             case "error":                 $this->error = mysqli_error($this->link);                 break;         }     } } 

all other lines of code in pipe.php run, email, no data added database. know why, , if so, how can make data inserted?

you should use single quote , mysql_real_escape_string method if want these quotes escaped in data. here example :

$emailbody = mysql_real_escape_string($mail->getplainbody()); $emailsubject = mysql_real_escape_string($mail->getsubject()); $from = mysql_real_escape_string($mail->getheader("from"));  $db->query("insert tickets values ($id, '$emailsubject', '$emailbody', '$from')"); 

from php documentation :

mysql_real_escape_string — escapes special characters in string use in sql statement


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -