0

I want to get "post_title" where the ID become $_GET['id']. For this, I created it but wont respond a reply.

// Informações do Banco de Dados
$db['server'] = '127.0.0.1';
$db['user'] = 'user';
$db['pass'] = 'pass';
$db['database'] = 'databasename';

$connect = mysql_connect($db['server'],$db['user'],$db['pass'],$db['database']) or print (mysql_error());
mysql_select_db($db['database'], $connect);
////////////////////////////////////////////////////////////////////////////////////////

if ($_GET['id'] == NULL){
    print "Não Encontrado!";
    return false;
}
$idPego = $_GET['id'];
echo 'Número: ';
echo $idPego;

$livrotitle = mysql_query("SELECT post_title FROM _posts WHERE id='$_GET['id']' LIMIT 1");
$livro['titulo'] = mysql_result($livrotitle);
NullPoiиteя
  • 56,591
  • 22
  • 125
  • 143
  • 4
    what error you getting? i dont see anything wrong except ***Deprecated API***, ***XSS Vulnerability*** and ***SQL Injection Vulnerability*** – NullPoiиteя Nov 21 '15 at 06:02
  • 6
    [**Please, don't use `mysql_*` functions in new code**](http://stackoverflow.com/q/12859942). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://uk.php.net/manual/en/function.mysql-connect.php)? Learn about [*prepared statements*](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). – Rizier123 Nov 21 '15 at 06:03
  • 2
    What does it mean "not working"? Do you get any errors? Add [error reporting](http://php.net/manual/en/function.error-reporting.php) at the top of your file(s): `ini_set("display_errors", 1);` – Rizier123 Nov 21 '15 at 06:05
  • 4
    You are missing the `int $row` param of [`string mysql_result ( resource $result , int $row [, mixed $field = 0 ] )`](http://php.net/manual/en/function.mysql-result.php) – Sean Nov 21 '15 at 06:05

1 Answers1

4

Replace this

$livrotitle = mysql_query("SELECT post_title FROM _posts WHERE id='$_GET['id']' LIMIT 1");

with

 $livrotitle = mysql_query("SELECT post_title FROM _posts WHERE id='$idPego' LIMIT 1");

Note: Insert query will throw error since it has syntax error id='$_GET['id']'

Rasclatt
  • 12,498
  • 3
  • 25
  • 33
kannan
  • 691
  • 5
  • 17