3 回答
TA贡献1780条经验 获得超5个赞
如果您使用的是 GET 方法,请使用 $_GET 来获取提交表单数据。
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
session_start();
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if(isset($_GET["action"])&&($_GET["action"]=="versave")){
$gp_name = $_GET['gp_name'];
$version = $_GET['version'];
$query_vers = "CREATE TEMPORARY TABLE IF NOT EXISTS tmp SELECT * from `gp_info` WHERE `gp_name`= '$gp_name';
UPDATE tmp SET `version` = '$version';
ALTER TABLE tmp DROP id;
INSERT INTO `gp_info` SELECT 0, tmp.* FROM tmp";
if(mysqli_multi_query($conn, $query_vers)){
echo "query exicute";
}
//header("Location: gp_data.php");
}
?>
<form id="verForm" name="versaveForm" method="get">
<input type="hidden" name="action" value="versave">
<div>
<input type="text" id="gp_name" name="gp_name">
<input type="text" id="version" name="version">
</div>
<input type="submit" name="vers" value="Version" id="versave">
</form>
TA贡献1799条经验 获得超8个赞
使用mysqli_query
代替mysql_query
。它在新版本中已被弃用,php
并且仅使用了 1 个参数。我们没有在mysql_query
.
mysql_query($connect, $query_vers);
将此行更新为 mysqli_query
mysqli_query($connect, $query_vers);
TA贡献1828条经验 获得超13个赞
使用 PDO 而不是mysql_query()
<?php
if(isset($_POST["action"])&&($_POST["action"]=="versave")) {
$query_vers = "CREATE TEMPORARY TABLE tmp SELECT * from `gp_info` WHERE `gp_name`= gp_name;
UPDATE tmp SET `version` = version;
ALTER TABLE tmp DROP id;
INSERT INTO `gp_info` SELECT 0, tmp.* FROM tmp;
DROP TABLE tmp";
$db = new PDO('mysql:host=localhost;dbname=test', 'username', 'passwd');
$st = $db->exec($query_vers);
}
- 3 回答
- 0 关注
- 187 浏览
添加回答
举报