0

I have this code below. I want to return whether if the row exist on my database or not. Thanks!

 $con = $this->con();
        $sql = "SELECT `id`, `user`, `data_name`, `title`, `price`, `category`, `brand`, `description`, `tags`, `date_added` FROM `mktdata` WHERE user='$this->user' AND data_name='$this->formName'";
        $data = $con->prepare($sql);
        $data->execute();
        $result = $data->fetchAll();
        return $result;
  • check this - https://stackoverflow.com/questions/11974613/pdo-php-check-if-row-exist – Rajkumar R Jun 04 '21 at 05:20
  • Also check prepared statement syntax. `$this->{user,formName}` should be in these `execute()` arguments rather than string concatenation. – danblack Jun 04 '21 at 05:30
  • This query will execute properly. But im not sure how to return it true so I can put an if else to my php code. – Kojak Eugenio Jun 04 '21 at 05:46
  • Lol there is no point using prepared statements if you're not going to parameterise the variables, it still leaves you vulnerable to SQL injection attacks. – ADyson Jun 04 '21 at 06:53
  • Anyway, read the links above if you want to know how to check whether a row exists. – ADyson Jun 04 '21 at 06:53
  • Sorry. I am a newbie and just typed what i saw on youtube tutorials. lol. The link on the top worked! Thanks – Kojak Eugenio Jun 04 '21 at 20:52

0 Answers0