-1

I'm doing a simple project on raspberry Pi where I created a table of login in Mysql database where i write login username and password I created HTML and PHP in var/www/html and the HTML page work properly but when i try to log in i get

This page isn’t working192.168.1.26 is currently unable to handle this request. HTTP ERROR 500 on the PHP page I tried to restart apache2 by sudo service apache2 start but I get

Job for apache2.service failed because the control process exited with an error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
  • My database show results
  • I didn't grant any privileged
  • my PHP shows when I typed my IP
  • when I try to access any database in PHPMyAdmin it shows at the bottom

mysqli::real_connect(): (HY000/1045): Access denied for user 'phpmyadmin'@' Connection for controluser as defined in your configuration failed.localhost' (using password: YES)

my php code

 <?php
    
    $host="localhost";
    
    $username="root";
    
    $password="(my mysql root password)";
    
    $db_name="ssn"; #name of my data base
    
    $tbl_name="login"; # my table name
    
    $conn = mysql_connect("$host", "$username", "$password")or die("cannot connect");
    
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $myusername=$_POST['usr'];
    
    $mypassword=$_POST['pwd'];
    
    $myusername = stripslashes($myusername);
    
    $mypassword = stripslashes($mypassword);
    
    $myusername = mysql_real_escape_string($myusername);
    
    $mypassword = mysql_real_escape_string($mypassword);
    
    $sql="select * from $tbl_name where passwd='$mypassword' AND name='$myusername'";
    
    $result=mysql_query($sql,$conn);
    
    $count=mysql_num_rows($result);
    
    if ($count == 1)
    {
    echo ":) :) LOGIN SUCCESS :) :) ";
    }
    
    else 
    {
    echo ":( :( AUTHETICATION FAILURE :( :( ";
    }
    
    ?>

#My html code

<html>

<body>

<form method="post" action="logindb.php">

UserName:<input type="text" name="usr"><br><br>

Password:<input type="password" name="pwd"><br><br>

<center><input type="submit" name="sub" value="Login"/></center><br><br>

</form>

</body>

</html>

i tried to run sudo systemctl status apache2to know the issue and i got this sudo systemctl status apache2

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-05-29 02:56:28 CET; 1min 2s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3485 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 125ms

May 29 02:56:28 raspberrypi systemd[1]: apache2.service: Control process exited, code=exited, s>
May 29 02:56:30 raspberrypi apachectl[3488]: AH00558: apache2: Could not reliably determine the>
May 29 02:56:30 raspberrypi apachectl[3488]: (98)Address already in use: AH00072: make_sock: co>
May 29 02:56:30 raspberrypi apachectl[3488]: (98)Address already in use: AH00072: make_sock: co>
May 29 02:56:30 raspberrypi apachectl[3488]: no listening sockets available, shutting down
May 29 02:56:30 raspberrypi apachectl[3488]: AH00015: Unable to open logs
May 29 02:56:28 raspberrypi systemd[1]: apache2.service: Failed with result 'exit-code'.
May 29 02:56:30 raspberrypi apachectl[3485]: Action 'start' failed.
May 29 02:56:30 raspberrypi apachectl[3485]: The Apache error log may have more information.
May 29 02:56:28 raspberrypi systemd[1]: Failed to start The Apache HTTP Server.
lines 1-17/17 (END)...skipping...
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2022-05-29 02:56:28 CET; 1min 2s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3485 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
        CPU: 125ms

May 29 02:56:28 raspberrypi systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
May 29 02:56:30 raspberrypi apachectl[3488]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerN>
May 29 02:56:30 raspberrypi apachectl[3488]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:80
May 29 02:56:30 raspberrypi apachectl[3488]: (98)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80
May 29 02:56:30 raspberrypi apachectl[3488]: no listening sockets available, shutting down
May 29 02:56:30 raspberrypi apachectl[3488]: AH00015: Unable to open logs
May 29 02:56:28 raspberrypi systemd[1]: apache2.service: Failed with result 'exit-code'.
May 29 02:56:30 raspberrypi apachectl[3485]: Action 'start' failed.
May 29 02:56:30 raspberrypi apachectl[3485]: The Apache error log may have more information.
  • Aside from any other issues, `mysql_*()` functions were removed as of PHP 7. You should be using `mysqli_*()`, or `PDO`. – Tangentially Perpendicular May 29 '22 at 02:00
  • @TangentiallyPerpendicular I'm not familiar with the new update where exactly should I change to mysqli_*() or PDO ? – tessa Brock May 29 '22 at 02:24
  • please focus your question on one thing at a time. I would suggest starting with the fact the your webserver apparently isn't even running... before you worry about your database connection you should try to solve this issue. – But those new buttons though.. May 29 '22 at 02:33
  • @EatenbyaGrue I recently worked with NGINX + PHP for an RFID project and it was working fine but the Nginx page kept having errors for no reason so I decided to install apache I think that might be the issue...not quite sure even the PHP page appears for me when I type my IP address but apache doesn't start when I run it... – tessa Brock May 29 '22 at 03:15
  • 1
    There's no such thing as "errors for no reason". – But those new buttons though.. May 29 '22 at 03:18
  • @tessa The 'new update' was PHP 7, and it was released nearly seven years ago. The current version is 8.1, with 8.2 due in November 2022. See [this question](https://stackoverflow.com/q/1390607/14853083) for help on migration. – Tangentially Perpendicular May 29 '22 at 04:06

1 Answers1

0

That's telling you that the username, host, and password you are using isn't allowed to connect to your server. Check your mysql permission tables.

  • i granted all priviliged by GRANT ALL PRIVILEGES ON ssn. * TO 'root'@'localhost'; and it still not working :/ – tessa Brock May 29 '22 at 02:22
  • Try adding this to the top of your PHP file and see what errors it shows: ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL & ~E_NOTICE); – Tracey Wright May 29 '22 at 02:31
  • i got the following Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/html/test/logindb.php:13 Stack trace: #0 {main} thrown in /var/www/html/test/logindb.php on line 13 – tessa Brock May 29 '22 at 03:21
  • Ok, so line 13 is this: $conn = mysql_connect("$host", "$username", "$password")or die("cannot connect"); It's telling you that the function mysql_connect isn't available. The mysql_* functions are deprecated. They shouldn't be used. You should be using mysqli or PDO instead. It's a pretty easy change. Take a look at the format for both here and pick one: https://www.php.net/manual/en/mysqlinfo.api.choosing.php – Tracey Wright May 29 '22 at 16:38