通过 php 更新 mySQL 后需要帮助创建自定义成功和失败页面

发布于 2024-12-10 07:23:46 字数 724 浏览 7 评论 0原文

如何更改我的脚本,以便成功的更新将自动将我带到网页,而错误将把我带到失败的网页?

我想要两个不同的网页代表成功或失败。

感谢您的帮助。

埃里克

<?PHP
session_start();
?>

<?php

$type=$_POST['type'];
$part_no=$_POST['part_no'];
$description=$_POST['description'];
$count=$_POST['count'];
$min=$_POST['min'];
$max=$_POST['max'];

$db="naturan8_hero";

$link = mysql_connect("localhost", "XXXXXX", "XXXXXX");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query(" UPDATE cartons_current SET type='$type' , description='$description' ,
count='$count' , min='$min' , max='$max' WHERE part_no='$part_no'");
echo "Record Updated";
mysql_close($link);
?>

How do I change my script so that a successful update will automatically take me to a web page and an error will take me to a fail web page?

I would like to have two different web pages representing success or failure.

Thank you for your help.

Erik

<?PHP
session_start();
?>

<?php

$type=$_POST['type'];
$part_no=$_POST['part_no'];
$description=$_POST['description'];
$count=$_POST['count'];
$min=$_POST['min'];
$max=$_POST['max'];

$db="naturan8_hero";

$link = mysql_connect("localhost", "XXXXXX", "XXXXXX");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
mysql_query(" UPDATE cartons_current SET type='$type' , description='$description' ,
count='$count' , min='$min' , max='$max' WHERE part_no='$part_no'");
echo "Record Updated";
mysql_close($link);
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

单挑你×的.吻 2024-12-17 07:23:47

简单如 ABC - 替换

mysql_query(" UPDATE cartons_current ...");
echo "Record Updated";

为:

if(mysql_query("UPDATE cartons_current ...") && (@mysql_affected_rows() > 0)) {
    header('Location: success.htm');
}else{
    header('Location: fail.htm');
}

mysql_query()
(...) 对于其他类型的 SQL 语句,INSERT、UPDATE、DELETE、DROP 等,mysql_query() 在成功时返回 TRUE,在错误时返回 FALSE。

mysql_affected_rows() - 获取最后受影响的行数INSERT、UPDATE、REPLACE 或 DELETE 查询

simple as ABC - replace

mysql_query(" UPDATE cartons_current ...");
echo "Record Updated";

with:

if(mysql_query("UPDATE cartons_current ...") && (@mysql_affected_rows() > 0)) {
    header('Location: success.htm');
}else{
    header('Location: fail.htm');
}

mysql_query()
(...) For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

mysql_affected_rows() - Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query

回忆那么伤 2024-12-17 07:23:46
$query = mysql_query(" UPDATE cartons_current SET type='$type' , description='$description',count='$count' , min='$min' , max='$max' WHERE part_no='$part_no'");

if($query) {
  header('Location: success.htm');
}else{
  header('Location: fail.htm');
}
$query = mysql_query(" UPDATE cartons_current SET type='$type' , description='$description',count='$count' , min='$min' , max='$max' WHERE part_no='$part_no'");

if($query) {
  header('Location: success.htm');
}else{
  header('Location: fail.htm');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文