So I'm working on a URL shortener and in my database I have an id,url,code, and created. So basically my code goes through and checks if the url entered exists then returns the code, but for some reason the code isn't being returned. Here's what I got.
My Shorten.php class
<?php
class Shortener{
protected $db;
public function __construct(){
$this->db = new mysqli('localhost','root','wayne123','s');
}
protected function generateCode($num){
# code...
}
public function makeCode($url)
{
$url = trim($url);
if(!filter_var($url, FILTER_VALIDATE_URL)){
return '';
}
$url = $this->db->escape_string($url);
//Check if exists
$exists = $this->db->query("SELECT code FROM links WHERE url = '{$url}'");
if($exists->num_rows){
return $exists->fetch_objects()->code;
}
else{
}
}
public function getUrl($code){
# code...
}
}
And my shorten.php
<?php
session_start();
require_once 'classes/Shortener.php';
$s = new Shortener;
if (isset($_POST['url'])){
$url = $_POST['url'];
if($code = $s->makeCode($url)){
echo $code;
}else{
//Problem
}
}
http://www.google.comin the DB, so it should echogoogle123. And not returning at the moment @briosheje