mysql - PHP URL Shortener: Shortener.php returning an error message -


so creating url shortener site based off of youtube tutorial (phpacademy) due lack of experience in php , mysql, feel i'm picking quickly, receive error message when submitting url.

parse error: syntax error, unexpected 'update' (t_string) in /home/langers/public_html/r/shorten/classes/shortener.php on line 37

however ,in code, line mentions , t_string 'update' implies unexpected, needed in tutorial.

<?php class shortener {     protected $db;      public function __construct() {         //demo purposes         $this->db = new mysqli('localhost', 'langers_langers', 'password','langers_website');     }      protected function generatecode($num){         return base_convert($num, 10, 36);     }      public function makecode($url){         $url = trim($url);          if(!filter_var($url, filter_validate_url)) {             return '';         }          $url = $this->db->escape_string($url);          //check if url exists         $exists = $this->db->query("select code links url ='{$url}'");          if($exists->num_rows){             return $exists->fetch_object()->code;         } else {          //insert record without code         $insert->$this->db->query("insert links (url, created) values ('{$url}', now());          //generate code based on id         $code = $this->generatecode($this->db->insert_id);          //update record         $this->db->query("update links set code = '{$code}' url = '$url'");          return $code;         }     }      public function geturl($code){      } }  ?> 

any ideas on how can fix still updates mysql database?

thanks

the error happens before, when miss closing quotes at

//insert record without code $insert->$this->db->query("insert links (url, created) values ('{$url}', now()); 

please note you're using $insert if object, isn't. perhaps meant:

$insert = $this->db->query("insert links (url, created) values ('{$url}', now())"); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -