试图使用PHP和HTML代码PhpStorm向MySQL数据库添加新列

问题描述 投票:-1回答:1

试图使用php和html代码向mysql数据库添加新列,但是代码不起作用,只是在Safari浏览器中出现白页,Chrome浏览器告诉我

此页面无法正常运行localhost当前无法处理此请求。HTTP错误500

我正在使用MAMP /Applications/MAMP/bin/php/php7.4.1/bin/php-cgi -e -b 127.0.0.1:49949

home.html代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="data.php" method="post">
    <h2>newdata</h2>
    <label>enter data:</label>
    <input type="text" name="nclm" >

    <input type="submit" name="newdata" value="newdata">

</form>
</body>
</html>

database.php

<?php
$servername='127.0.0.1';
$username='root';
$password='12345678';
$dbname = "company";
$conn=mysqli_connect($servername,$username,$password,"$dbname");
if(!$conn){
    die('Could not Connect My Sql:' .mysql_error());
}
?>

data.php

<?php
include_once 'database.php';

    if(isset($_POST['newdata'])) {

        $nclm = $_POST['nclm'];

        $added = mysql_query("ALTER TABLE employees ADD .'$nclm'. VARCHAR(50) NOT NULL ");

        if ($added !== FALSE) {
            echo("The column has been added.");
        } else {
            echo("The column has not been added.");
        }
    }
    ?>
php html mysql phpstorm mamp
1个回答
0
投票
您需要更改此行:
© www.soinside.com 2019 - 2024. All rights reserved.