简体   繁体   English

更新不起作用

[英]update doesn't work

I've been trying to update a table in my database triggered by an UPDATE button but somehow it doesn't work, whenever I change the values then click the update button, it just refreshes the values, no update/change happens..please help 我一直在尝试通过UPDATE按钮触发更新数据库中的表,但是无论如何,当我更改值然后单击update按钮时,它不起作用,它只是刷新值,没有更新/更改发生..请救命

<?php
session_start();
require_once("dbconnect.php");

$webhost=$_GET["webhost"];

$requesttitle=$_POST["requesttitle"];
$requesturl=$_POST["requesturl"];
$requestcap=$_POST["requestcap"];
$requestdestype=$_POST["requestdestype"];
$requestdbtype=$_POST["requestdbtype"];
$deptname=$_POST["deptname"];
$contactname=$_POST["contactname"];
$contactnum=$_POST["contactnum"];
$contactemail=$_POST["contactemail"];
$startdate=$_POST["startdate"];
$enddate=$_POST["enddate"];

if(isset($_POST['button']))
{

$sql="update webhostrequest set requesttitle='$requesttitle', ";
    $sql.="requesturl='$requesturl', requestcap='$requestcap', ";
    $sql.="requestdestype='$requestdestype', requestdbtype='$requestdbtype', ";
    $sql.="deptname='$deptname', contactname='$contactname', ";
    $sql.="contactnum='$contactnum', contactemail='$contactemail' ';
    $sql.="startdate='$startdate',  enddate='$enddate', recentact=now() where requestid='$id'";

$result = mysql_query($sql) or die ("Error in editing item. ".mysql_error());
}
header("location: editwebhost.php?webhost=$webhost");
exit;

?>

$id is not set in your code. 您的代码中未设置$ id。 So as the "WHERE" stipulates only update the entry with requestid =$id, it's probably the missing link? 因此,由于“ WHERE”规定仅使用requestid = $ id更新条目,这可能是缺少的链接吗?

Try echoing $sql to the page so you can see what query your code is producing. 尝试将$ sql回显到页面,以便您可以查看代码正在生成的查询。 Then try running the query directly (through phpMyAdmin or however you access your db). 然后尝试直接运行查询(通过phpMyAdmin,或者访问数据库)。

Are you getting any error from your "or die()"? 您是否从“ or die()”中得到任何错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM