gpt4 book ai didi

php - 将值复制到另一个 mysql 数据库

转载 作者:行者123 更新时间:2023-11-30 22:42:48 25 4
gpt4 key购买 nike

我有一个表格,显示从表单发送的字段。有一些按钮可以通过选择 id 来编辑或删除选定的行。我想添加一个按钮,将选定的行插入到另一个表中。我无法让它工作。

这是表格的代码:

    <?php
/*
VIEW.PHP
Displays all data from 'players' table
*/

// connect to the database
include('config2.php');

// get results from database
$result = mysql_query("SELECT * FROM articles")
or die(mysql_error());

// display data in table
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Author</th> <th>Email</th> <th>Title</th> <th>Poem</th> <th>id</th>";

// loop through results of database query, displaying them in the table
while($row = mysql_fetch_array( $result )) {

// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . $row['Name'] . '</td>';
echo '<td>' . $row['Email'] . '</td>';
echo '<td>' . $row['title'] . '</td>';
echo '<td>' . $row['content'] . '</td>';
echo '<td>' . $row['id'] . '</td>';
echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>';
echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>';
echo '<td><a href="publish.php?id=' . $row['id'] . '">Publish</a></td>';
echo "</tr>";
}

// close table>
echo "</table>";
?>

下面是删除函数的代码:

 // connect to the database
include('config2.php');

// check if the 'id' variable is set in URL, and check that it is valid
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
// get id value
$id = $_GET['id'];

// delete the entry
$result = mysql_query("DELETE FROM stories WHERE id=$id")
or die(mysql_error());

// redirect back to the view page
header("Location: secret.php");
}
else
// if id isn't set, or isn't valid, redirect back to view page
{
header("Location: secret.php");
}

我认为将行插入其他表的函数应该是这样的,但它不起作用

// connect to the database
include('config2.php');

// check if the 'id' variable is set in URL, and check that it is valid
if (isset($_GET['id']) && is_numeric($_GET['id']))
{
// get id values
$id = $_GET['id'];
$name = $_GET['name'];
$email = $_GET['email'];
$title = $_GET['title'];
$content = $_GET['content'];


//upload
$result = mysql_query("INSERT into publish (name, email, title, content)
VALUES WHERE name=$name, email=$email, title=$title, content=$content")
or die(mysql_error());

// redirect back to the view page
header("Location: secret.php");
}
else
// if id isn't set, or isn't valid, redirect back to view page
{
header("Location: secret.php");
}

我是新手,所以不确定在这种情况下正确的语法是什么样的

最佳答案

    Using select query  

$id = $_GET['id'];
$result = mysql_query("select *stories WHERE id=$id")
or die(mysql_error());
$row = mysql_fetch_array( $result );
$query= mysql_query("INSERT INTO publish (name, email, title, content)
VALUES ('$row['Name']','$row['Email']',$row['title'],$row['content'])");

关于php - 将值复制到另一个 mysql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30650741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com