更新查询问题... [英] Update query issue...
问题描述
大家好 - 提前感谢任何帮助。
我正在尝试编写一个简单的更新脚本。事实上,我正在重复使用之前已成功使用过的代码
,但我无法弄清楚为什么它不是工作的b $ b。脚本完成没有任何错误,但实际上并没有
更新数据库。
此外,检查同名是查询工作正常,如果找到重复,将返回正确的
错误。
再次感谢!
Shane
这是代码 - 非常简单...
<?PHP
require(''标题。 php'');
require(''config.php'');
mysql_connect($ dbserver,$ username,$ password)
或死亡(无法连接);
@mysql_select_db($ database)
或死亡(无法选择数据库);
$ id = $ _ POST [''id''];
$ name = $ _ POST [''name''];
$ description = $ _ POST [''description''];
$ show = $ _ POST [''show''];
?>
< TABLE width = 500 cellpadding =" 15">
< TR>
< ; TD>
< H1>< font face =" verdana">编辑项目< / H1>
< font face =" ; verdana">
& lt;?php
echo" $ id< BR>" ;;
echo" $ name< BR>";
echo" $ description< BR>" ;;
echo" $ show< BR>" ;;
$ query =" SELECT * FROM project WHERE name =''$ name''" ;;
$ result = mysql_query($ query);
$ num = mysql_numrows ($ result);
// echo $ num;
//检查是否已有一个名为<的项目br />
//我们正试图改为。如果id相同则忽略
//因为这意味着没有更改名称。
if($ num 0){
$ conflictid = mysql_result($ result,0," id");
if(!($ id == $ conflictid)){
die (错误:数据库中已经有一个带有
名称的项目。请再试一次。);
}
否则{
$ query =" UPDATE project SET name =''$ name'',
description =''$ description'',
show =''$ show''
WHERE id = $ id" ;;
mysql_query($ query);
echo" Record Updated" ;;
}
}
否则{
$ query =" UPDATE project SET name =''$ name'',
description =''$ description'',
show =''$ show''
WHERE id = $ id" ;;
mysql_query($ query);
echo" Record Updated" ;;
}
mysql_close();
?>
< / TD>
< / TR>
< / TABLE>
<?php
require(''footer.php'');
?>
dbserver,
用户名,
密码)
或死亡(无法连接);
@mysql_select_db(
Hi all - thanks in advance for any help.
I am trying to write a simple update script. In fact, I am re-using code
that I''ve used before (successfully) but I can''t figure out why it is not
working. The script completes without any errors, but does not actually
update the database.
Also, the "check for same name" query works fine, and will return the proper
error if a duplicate is found.
Thanks again!
Shane
Here is the code - pretty simple...
<?PHP
require(''header.php'');
require(''config.php'');
mysql_connect($dbserver,$username,$password)
or die( "Unable to connect");
@mysql_select_db($database)
or die( "Unable to select database");
$id=$_POST[''id''];
$name=$_POST[''name''];
$description=$_POST[''description''];
$show=$_POST[''show''];
?>
<TABLE width=500 cellpadding="15">
<TR>
<TD>
<H1><font face="verdana">Edit Project</H1>
<font face="verdana">
<?php
echo "$id <BR>";
echo "$name <BR>";
echo "$description <BR>";
echo "$show <BR>";
$query="SELECT * FROM project WHERE name = ''$name''";
$result=mysql_query($query);
$num=mysql_numrows($result);
//echo $num;
//Check to see if there is already a project with the name
//we are trying to change to. Ignore if the id is the same
//since this just means there was no name change.
if($num 0){
$conflictid=mysql_result($result,0,"id");
if(!($id==$conflictid)){
die("Error: There is already a project with that
name in the database. Please try again.");
}
else{
$query="UPDATE project SET name=''$name'',
description=''$description'',
show=''$show''
WHERE id=$id";
mysql_query($query);
echo "Record Updated";
}
}
else{
$query="UPDATE project SET name=''$name'',
description=''$description'',
show=''$show''
WHERE id=$id";
mysql_query($query);
echo "Record Updated";
}
mysql_close();
?>
</TD>
</TR>
</TABLE>
<?php
require(''footer.php'');
?>
dbserver,
username,
password)
or die( "Unable to connect");
@mysql_select_db(
这篇关于更新查询问题...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!