我想将值从一个表单发送到将其发布到数据库的php文件,然后发送到发布相同值的另一个php文件,我该如何使用php执行此操作?
这是我的php
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $con);
$sql="INSERT INTO players (first_name, last_name, company, phone, email, zip, street, city, state, country, reasons, notes, callback)
VALUE
('$_POST[first_name]','$_POST[last_name]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[zip]','$_POST[street]','$_POST[city]','$_POST[state]','$_POST[country]','$_POST[reasons]','$_POST[notes]','$_POST[callback]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
感谢您的帮助。 (我很抱歉,如果这是重复的,我没有找到任何相关内容)
答案 0 :(得分:2)
在submit.php文件中
<?php
$con = mysql_connect("localhost","user","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $con);
$sql="INSERT INTO players (first_name, last_name, company, phone, email, zip, street, city, state, country, reasons, notes, callback)
VALUE
('$_POST[first_name]','$_POST[last_name]','$_POST[company]','$_POST[phone]','$_POST[email]','$_POST[zip]','$_POST[street]','$_POST[city]','$_POST[state]','$_POST[country]','$_POST[reasons]','$_POST[notes]','$_POST[callback]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
//Add more
$id = mysql_insert_id();
mysql_close($con);
header('Location: review.php?id=' . $id);
?>
然后从review.php文件中获取数据
<?php
$id = $_GET['id'];
//SELECT * FROM tbl ... WHERE id = $id
//Your code
?>