嗨,我想使用php将新列添加到名为task的表中。 香港专业教育学院尝试了多种方法,但是当我进入phpmyadmin时,那里没有新的列。 :当前代码
<?php
$date = date("d/m/Y");
$ip = $_SERVER['REMOTE_ADDR'];
$servername = "localhost";
$database = "webdata 2";
$username = "admin";
$password = "********";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "";
$sql = "INSERT INTO tasks (username) VALUES ('$ip')";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
答案 0 :(得分:0)
您编写的代码用于添加新行,如果要添加新列,则需要将变量$sql
更改为此代码
$sql = "ALTER TABLE table_name ADD [COLUMN] column_name column_definition";
有关更多信息,请访问此link