Hello, there is a secret page that can only be accessed via the login page by entering a password there. It’s necessary that the password be taken not from the page itself, but from the database.

<?php $connection = mysql_connect("localhost", "root", ""); $db = mysql_select_db("mydb"); mysql_query("SET NAMES 'cp1251'"); if(!$connection || !$db) { exit(mysql_error()); } $result1 = mysql_query("SELECT `password` FROM `pass` WHERE `id` = '30'"); mysql_close(); $p = $result1['password']; if($_GET['key'] !=md5('$p')) { header('location:login.php'); } ?> 

On the line of the $p variable, echo gives an error, help plz how to properly arrange.

The error itself:

Parse error: in Z: \ home \ Cascade \ www \ enter \ 30.php on line 13

Thanks in advance for your answers.

Closed due to the fact that off-topic participants Dmitriy Simushev , aleksandr barakin , PashaPash 31 Mar '16 at 8:53 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - aleksandr barakin, PashaPash
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Specify in which line there is an error and the text of the error itself. Otherwise, all this fortune telling on the coffee grounds - Dmitriy Simushev
  • Parse error: in Z: \ home \ Cascade \ www \ enter \ 30.php on line 13 If I am writing via echo Without it, I don’t enter a secret page at all. - John TRavolta
  • Variables in single quotes in php are not interpolated. Those. not replaced by the contents of the variable. So '$p' is exactly the string $ p. In the above code, there is no echo at all, so there can be no such error in this text. And it’s strange to take md5 from the database value, it would be more logical to keep md5 from the password in the database and not an open password - Mike
  • Thank you for propping up the variable in quotes :) Thank you very much. - John TRavolta
  • @JohnTRavolta, uh ... in your example code, there is no echo construction ... So what exactly is in the 13th line? - Dmitriy Simushev

1 answer 1

You need to process the result of the request. For example:

 $result1 = mysql_query("SELECT `password` FROM `pass` WHERE `id` = '30'"); mysql_close(); $row = mysql_fetch_object($result1); $p = $row->password; 
  • It did not help, it simply does not enter the page. Without echo it comes but with an error (in the given line $ p = $ result1 ['password'];), and without echo it does not come at all. - John TRavolta