简体   繁体   中英

PHP page is working locally, but not on the server

My PHP page is blank when I upload it to my server and navigate to it in a browser.

<form action="welcome.php" method="get">
    <input type="text" name="name" placeholder="enter first and last name" >
    <br />
    <input type="image" value="Submit" id="submit"/>
</form>

On the welcome.php page:

$fullName = $_GET['name'];
$firstName = explode(' ',trim($fullName));

<h2>Welcome <?php echo $firstName[0] ?>!</h2>

SOLVED . Permissions issue. The PHP file needed to be 644 , not 666 .

The problem:

<!– SHTML Wrapper – 500 Server Error –>

This is a silly Bluehost error. Typically related to file permissions. See here: http://www.bluehostforum.com/showthread.php?11101-SHTML-Wrapper-500-Server-Error-moving-to-a-new-box-helps

Just make sure that your file does not have the "world write" permission.

Try checking your server's Apache log file. This should give you some indication to the server error if any.

If you do not have access to the error log, add the following to the top of your PHP file. It will show any errors on the page you are viewing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

One of the easiest solutions is enabling FastCGI from the cPanel PHPConfig.

Just enable it and everything will work.

Viewing the source code, you have an internal server error (500). Googling the error, you have WordPress(?) or this affects it.

<!– SHTML Wrapper – 500 Server Error –>

According to this guide , it's a problem with PHP CGI and you need to fix it in your host' panel, or manually via the terminal.

This question is almost 10 years old, but I never saw this.

If you are using HostGator, do the following: go to cPanel –> MySQL Databases –> Add New User (set the password, and allow all or none of the query permissions – if you are a student then allow all permissions).

Now scroll down to "Add User To Database." Make sure the username you just created is linked to the database you are trying to use.

Here's a sample of how your code should look like:

// Server conditional values and connection
// This first if-statement connects to your localhost
if ($_SERVER['HTTP_HOST'] == 'localhost') {
        define('HOST', 'localhost');
        define('USER', 'root');
        define('PASS', '1550');
        define('DB', 'webPoll');
} else {
// Means that you are in a web server
        define('HOST', 'localhost');
        // localhost is the default parameter
        define('USER', 'kevin69_tacoUser'); 
        // add the username you just created
        define('PASS', 'hUIDnd193');
        // password for such username
        define('DB', 'kevin69_webPoll');
        // username_database
}
$conn = mysqli_connect(HOST, USER, PASS, DB);

Hope this helps someone out there!

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