似乎编辑/修改我的php表的id [英] Cant seem to EDIT/MODIFY my php table by id

查看:125
本文介绍了似乎编辑/修改我的php表的id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<?php
$con = mysql_connect("localhost","root");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }


mysql_select_db("database", $con);

if(!isset($_POST['submit'])){
$result = mysql_query("SELECT * FROM pleasework ORDER BY ID"); 
$row = mysql_fetch_array($result);
}

?>

<form action="?php echo $_SERVER['PHP_SELF'];?>" id="form2" method="post" name="form2">
<img id="close1" src="X.png" width="25" height="25" onclick ="div_hide1()">
<h2><font size="6">Please change existing data</font></h2>
<hr>
<br> 

     <font color="yellow">Change Name to: </font><input type="text" name="New" value="<?php echo $row['Name'];?>"/><br><br>
      <font color="yellow"> Change Cause to: </font> <input type="text" name="New1" value="<?php echo $row['Cause'];?>"/><br><br>
     <font color="yellow">Change Symptom to:  </font><input type="text" name="New2" value="<?php echo $row['Symptom'];?>"/><br><br>
      <font color="yellow"> Change Gene_affected to:  </font><input type="text" name="New3"value="<?php echo $row['Gene_affected'];?>" /><br><br>
      <input type="hidden" name="id" value="<?php echo $_GET['ID'];?>"/>
    <input type="submit" onclick="clicked(event)" />
</form>

<?php
if(isset($_POST['submit'])){
mysql_query("UPDATE pleasework SET Name= '$_POST[New]' WHERE ID='$_POST[id]'");
mysql_query("UPDATE pleasework SET Cause= '$_POST[New1]' WHERE     ID='$_POST[id]'");
mysql_query("UPDATE pleasework SET Symptom= '$_POST[New2]' WHERE ID='$_POST[id]'");
mysql_query("UPDATE pleasework SET Gene_affected= '$_POST[New3]' WHERE ID='$_POST[id]'");
echo "Change Successful<br>" ;
header("Location: databse.php");
mysql_close($con);
} 
else {}
?>

这是我的php文件。

  while($row = mysql_fetch_array($result))
            {
                 echo "<TR>";
             echo "<TD>" . $row['ID'] ."</TD>";
             echo "<TD>" . $row['Name'] . "&nbsp;&nbsp;&nbsp;&nbsp;</TD>";
             echo "<TD>" . $row['Cause'] . "&nbsp;&nbsp;&nbsp;&nbsp;</TD>";
             echo "<TD>" . $row['Symptom']. "&nbsp;&nbsp;&nbsp;&nbsp;</TD>"; 
             echo "<TD>" . $row['Gene_affected'] . "&nbsp;&nbsp;&nbsp;&nbsp;        </TD>";     
  echo "<TD><a href=\"delete.php?id=" . $row['ID'] ."\"><font     color='red'>Delete row</font></a> &nbsp;&nbsp;&nbsp;&nbsp;</TD>";

  echo "<TD><a href=\"edit.php?id=" . $row['ID'] ."\"><font     color='red'>modify</font></a> &nbsp;&nbsp;&nbsp;&nbsp;</TD>";
             echo "</TR>";
            }

这是有一个修改按钮链接到编辑的部分。 php文件。这里的错误是没有将表中的值带到编辑页面,然后提交表单不工作。帮助请

And this is the section which has a modify button that links to the edit.php file. The error here is that is doesnt bring over the values in the table to the editing page and then submitting the form doesnt work too. help please

推荐答案

您的代码显得有点困惑。

Your code appears a bit confused.

为什么要把修改后的例程后输出形式?特别是因为修改后你发送函数,如果以前有一些输出,则失败。

First of all, why to put the modify routine after output the form? Especially since after modify you send the header function, that fails if previously there are some output.

错误:您忘记在表单声明中正确打开php标记。以这种方式更改:

Note also a typo: you forgot to properly open the php tag in the form declaration. Change-it in this way:

 <form action="<?php echo $_SERVER['PHP_SELF'];?>" id="form2" method="post" name="form2">

主要的问题是你检查 $ _ POST [submit] / code>如果设置,但由于没有属性 name ,因此未设置。

The main problem is that you check if the $_POST[submit] if set, but this is not set, due to the absence of attribute name.

以这种方式更改:

 <input type="submit" name="submit" onclick="clicked(event)" />

现在你的脚本应该可以工作了(我没有测试sql)。

Now your script should work (I don't have tested the sql).

请注意,您的 UPDATE 例程是多余的:您可以通过这种方式将4语句减少为一个语句:

Please also note that your UPDATE routine is redundant: you can reduce the 4 statement to only one in this way:

 $result = mysql_query
 (
    "UPDATE pleasework SET Name='{$_POST[New]}', Cause='{$_POST[New1]}', Symptom='{$_POST[New2]}', Gene_affected='{$_POST[New3]}' WHERE ID={$_POST[id]}"
 );

关于PHP原始MySQL API:


此扩展程序自PHP 5.5.0起已弃用,自PHP 7.0.0起已被删除

This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0

这篇关于似乎编辑/修改我的php表的id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆