我有一个从数据库中填充数据的表单,然后用户修改数据或选择不修改任何内容,然后只需按下提交按钮即可UPDATE
进入数据库。我的问题是:
- 我不知道如何确定哪些字段修改了数据
如果数据已被修改,如何从表单中检索数据
LOGIN"); } else { include('../conect.php'); //如果是新字段,则添加一个条目 -begin if( (isset($_POST)) && (isset($_GET["nou" ])) && (!empty($_POST['content'])) &&(!empty($_POST['nume'])) && (!empty($_POST['cale'])) && (!empty( $_POST['ordine'])) ) { if( $_POST['select']!=""){ $nume=stripslashes($_POST['nume']); $cale=$_POST['cale'] ; $ordine=$_POST['ordine']; $id=$_POST['select']; $content = stripslashes($_POST['content']);
我将 XAMP 与 PHP 5.3 和 HeidiSQL 一起使用。这是我的代码
?>$result=mysql_query("SELECT * FROM categorii_menu WHERE id=$id"); $data=mysql_fetch_row($result); $grad=$data[2]; $result2=mysql_query("SELECT * FROM categorii_menu WHERE grad_categorie=$grad"); while($data=mysql_fetch_row($result2)) { if ($ordine==$data[2]) $ok=1; else $ok=0; } $result3=mysql_query("SELECT * FROM categorii_menu "); while($zata=mysql_fetch_row($result3)) { if($nume==$zata[1]) { echo "Deja se foloseste acest nume"; $z=1; break; } else $z=0; if(($ok==0)&&($z==0)) mysql_query("INSERT INTO categorii_menu(nume,nr_ordine,grad_categorie,cale,continut) VALUES ('$nume','$ordine','$grad','$cale','$content')"); else if (($ok==1)&&($z==0)) echo "Acest nr de ordine este deja luat"; } else{ $nume=stripslashes($_POST['nume']); $cale=$_POST['cale']; $content = stripslashes($_POST['content']); $grad=0; $ok=0; $nr_ordine=$_POST['ordine']; $result=mysql_query("SELECT * FROM categorii_menu WHERE grad_categorie=$grad"); while($data=mysql_fetch_row($result)){ if($data[2]==$nr_ordine) { $ok=1; } } $result3=mysql_query("SELECT * FROM categorii_menu "); while($zata=mysql_fetch_row($result3)){ if($nume==$zata[1]){ echo "Deja se foloseste acest nume"; $z=1; break; } else $z=0; } if(($ok==0)&&($z==0))mysql_query("INSERT INTO categorii_menu(nume,nr_ordine,cale,grad_categorie,continut) VALUES ('$nume','$nr_ordine','$cale','$grad','$content')"); else if(($ok==1)&&($z==0)) echo "Acest nr de ordine este deja luat"; } //adds an entry if it's a new field -end //retrieves the modified data from the populated form (but only if all fields are modified :( , i don't know how to overcome this inconvenience ) - begin else if ( ($_POST) && (isset($_GET["nou"])) ) echo"Nu ati completat toate campurile"; if( ($_POST) && (isset($_GET["id"])) && (!empty($_POST['content'])) &&(!empty($_POST['nume'])) && (!empty($_POST['cale'])) && (!empty($_POST['ordine'])) ) { if( $_POST['select']!=""){ $id=$_GET["id"]; $nume=$_POST['nume']; $cale=$_POST['cale']; $ordine=$_POST['ordine']; $select=$_POST['select']; $content = stripslashes($_POST['content']); $result=mysql_query("SELECT * FROM categorii_menu WHERE id=$select"); $data=mysql_fetch_row($result); $grad=$data[2]; $result2=mysql_query("SELECT * FROM categorii_menu WHERE grad_categorie=$grad"); while($data=mysql_fetch_row($result2)) { if ($ordine==$data[2]) $ok=1; else $ok=0; } $result3=mysql_query("SELECT * FROM categorii_menu "); while($zata=mysql_fetch_row($result3)){ if($nume==$zata[1]){ echo "Deja se foloseste acest nume"; $z=1; break; } else $z=0; } if(($ok==0)&&($z==0)){ $result2 = mysql_query("SELECT * FROM categorii_menu"); mysql_query("UPDATE categorii_menu SET nume='$nume' , nr_ordine='$ordine' , grad_categorie='$grad', cale='$cale' , continut='$content' WHERE id='$id'"); header('Location:lista_linkuri.php'); } else if(($ok==1)&&($z==0))echo"Acest nr de ordine este deja luat"; } else { $id=$_GET["id"]; $nume=$_POST['nume']; $cale=$_POST['cale']; $ordine=$_POST['ordine']; $content = stripslashes($_POST['content']); $grad=0; $ok=0; $result=mysql_query("SELECT * FROM categorii_menu WHERE grad_categorie=$grad"); while($data=mysql_fetch_row($result)){ if($data[2]==$ordine) { $ok=1; } } $result3=mysql_query("SELECT * FROM categorii_menu "); while($zata=mysql_fetch_row($result3)){ if($nume==$zata[1]){ echo "Deja se foloseste acest nume"; $z=1; break; } else $z=0; } if(($ok==0)&&($z==0)){ mysql_query("UPDATE categorii_menu SET nume='$nume',nr_ordine='$ordine',cale='$cale',grad_categorie='$grad',continut='$continut') WHERE id='$id'"); header('Location:lista_linkuri.php'); } else if(($ok==1)&&($z==0))echo "Acest nr de ordine este deja luat"; } } else if( (isset($_GET["id"])) &&($_POST) ) echo"Nu ati completat toate campurile" ; //retrieves the modified data from the populated form (but only if all fields are modified :( , i don't know how to overcome this inconvenience ) - end }
编辑页面
}); //initializare megamenu ddmegamenu.docinit({ menuid:'solidmenu', dur:200 })// Theme options theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,|,undo,redo,preview,|,forecolor,backcolor", theme_advanced_buttons3 : "removeformat,|,sub,sup,|,charmap,|,fullscreen", theme_advanced_buttons4 : "spellchecker,template", theme_advanced_toolbar_location : "top", theme_advanced_toolbar_align : "left", theme_advanced_statusbar_location : "bottom", // Skin options skin : "o2k7", skin_variant : "silver", // Drop lists for link/image/media/template dialogs template_external_list_url : "js/template_list.js", external_link_list_url : "js/link_list.js", external_image_list_url : "js/image_list.js", media_external_list_url : "js/media_list.js", // Replace values for the template plugin template_replace_values : { username : "Some User", staffid : "991234" }
<div class="butoane_lista_articole"> <a href="lista_linkuri.php">Inapoi la lista</a> </div> <div id="pagina_noua_link" class="camp_linkuri2" > <div id="zona-date" class="titlu_pagina_noua"> <form action="<?php $_PHP_SELF ?>" method="post"> <span class="span_edit">Meniuri</span> <select name="select"> <option value="">Pagina Principala Noua</option> <?php $result=mysql_query("SELECT * FROM categorii_menu WHERE grad_categorie=0"); while($data=mysql_fetch_assoc($result)){ ?> <option value="<?php echo $data['id']; ?>" <?php if($data['id']!="") {echo "selected"; ?> > <?php echo $data['nume'];}?></option> <?php } ?> </select> </div> <?php if(isset($_GET["id"])){ $id=$_GET["id"]; $result=mysql_query("SELECT * FROM categorii_menu WHERE id=$id;"); $data=mysql_fetch_row($result); echo '<label for="nume">Nume</label><input type="text" value="'.$data[1].'"name="nume" class="input_text"/>'; echo '<label for="cale">Cale</label><input type="text" value="'.$data[4].'"name="cale" class="input_text"/>'; echo '<label for="ordine">Nr ordine</label><input type="text" value="'.$data[2].'"name="ordine" class="input_text"/>'; } else {?> <label for="nume">Nume</label><input type="text" name="nume" class="input_text" /> <label for="cale">Cale</label><input type="text" name="cale" class="input_text"/> <label for="ordine">Nr ordine</label><input type="text" name="ordine" class="input_text"/> <?php }?> </div> <div id="articol_link"> <textarea name="content" style="width :100%; height:300px;"> <?php if(isset($_GET["id"])){ $id=$_GET["id"]; $v2 = mysql_query("SELECT * FROM categorii_menu WHERE id=$id "); $id2 = mysql_fetch_row($v2); echo $id2[6]; } ?> </textarea> </div> <input type="submit" name="submit" value="<?php if(isset($_GET["id"])) echo "Salvare Modficari "; else echo "Adauga pagina";?> " class="button2"/> </form>