2

The issue is arising when I am trying to call the query; I don't see a problem with the logic of the code, but it still wants to throw an error. Line 11 is where the fetch_assoc() function is.

$mysqli->query("SELECT url FROM urls WHERE url_short = '" . $short . "'") or die($mysqli->error);
$result = $query->fetch_assoc();
$Redir = filter_var($result, FILTER_VALIDATE_URL);

$short is set as a $_GET variable, whereas I've tried hard coding it in; to no avail.

Liam
  • 87
  • 1
  • 6

2 Answers2

0

Doing it in wrong way -

$query = $mysqli->query("SELECT url FROM urls WHERE url_short = '" . $short . "'");
$result = $query->fetch_assoc();
Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
  • 1
    OP is using OO style, not Procedural style, so connection is not needed. see the manual http://php.net/manual/en/mysqli.query.php – Sean May 13 '15 at 04:34
  • Setting the $query variable before running the actual query seemed to have fixed the issue. Totally forgot that $query->fetch_assoc was reading from an actual query; had thought $query was defined in OOP as the returning query. – Liam May 13 '15 at 04:44
0

You are trying to fetch from the variable $query which is not definied (at least in the code snipped you postet). Also you query into $mysqli and not into $query.

Try this one:

$result = $mysqli->query("SELECT url FROM urls WHERE url_short = '" . $short . "'") or die($mysqli->error);

while ($row = $result->fetch_assoc()) {

}
bish
  • 3,381
  • 9
  • 48
  • 69