简体   繁体   中英

PHP wont connect to Apache/SQL server

I'm having a problem with running my PHP code and running my local apache24 server.

In html i have made a form ,

<form method="post" action="./php/submit.php">
                 <div class="submitrow">
                    <div class="col-25">
                        <label for="fname">Altcoin name*</label>
                    </div>
                    <div class="col-75">
                        <input type="text" name="altcoinName" placeholder="Ethereum" maxlength="20" required>
                    </div>
                 </div>

                <div class="submitrow">
                    <div class="col-25">
                        <label for="fname">Altcoin symbol*</label>
                    </div>
                    <div class="col-75">
                        <input type="text"  name="altcoinSymbol" placeholder="ETH" maxlength="5" required>
                    </div>
                </div> 
 </form>

When I submit the form I want to run this PHP script that sends the data from the form into my local SQL server, that im running with apache24 and phpmyadmin. When I "Submit" my form in html the PHP code is not getting executed it just appears in my browsers.

<?php
        $altcoinName = filter_input(INPUT_POST, 'altcoinName');
        $altcoinSymbol = filter_input(INPUT_POST, 'altcoinSymbol');
        if (!empty($altcoinName)){
        if (!empty($altcoinSymbol)){
            $host = "localhost/phpmyadmin";
            $dbusername = "root";
            $dbpassword = "";
            $dbname = "servertest";

            //create connection
            $conn = new mysqli ($host, $dbusername, $dbpassword, $dbname);

            if (mysqli_connect_error()){
                die('Connect Error ('. mysqli_connect_errno() .') '
                . mysqli_connect_error());     
            } else {
                $sql = "INSERT INTO submit (altcoinName, altcoinSymbol)
                values ('$altcoinName','$altcoinSymbol')";
                if ($conn->query($sql)){
                    echo "New record is inserted succesfully";
                } else {
                    echo "Error: ". $sql ."<br>". $conn->error;
                }
                $conn->close();
            }

        } else {
            echo "altcoin symbol should not be empty";
            die();
        }

        } else {
            echo "altcoin name should not be empty";
            die();
        }
?>

In the CMD I went to apache folder and started the httpd (httpd -k start). This error is what i got:

(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted.  : AH00072: make_sock: could not bind to address [::]:80
(OS 10048)Only one usage of each socket address (protocol/network address/port) is normally permitted.  : AH00072: make_sock: could not bind to address 0.0.0.0:80
AH00451: no listening sockets available, shutting down
AH00015: Unable to open logs

So I searched what port 0.0.0.0:80 did with netstat -a -o And it is LISTENING .

Does anybody got an Idea what I could have done wrong or how I could fix this? I would really appreciate that,

Thanks

you should grant execute access in the directory, usually set already in /var/www/html/ . But if you are using a site inside a your home directory like /home/username/public_site/ then you need to allow execution of scripts in this directory as well.

If your apache is running, but PHP isn't, PHP may not be configured to run from apache.

Methodically go through each step here:

http://php.net/manual/en/install.unix.apache2.php

If its a prebuilt Apache/PHP binary, start with step 6 onward to be sure the PHP side is configured. If in doubt, rebuild the binary :)

Also, while troubleshooting these sorts of things, there are form issues you can encounter, as well as just Apache/PHP configuration issues. To verify that at the least Apache is configured properly with PHP, put a php_info() test page in your web root.

If that works, and the form submission doesn't, you may have two seperate issues.

http://php.net/manual/en/function.phpinfo.php

My gut feeling is that you just need to be sure that step 7 is done, but I've been wrong before. And don't forget, before you test changes, to restart httpd / apache24 each time you make a change to any Apache or PHP file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM