Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Błąd w kodzie
Forum PHP.pl > Forum > Przedszkole
ayo1001
  1. <html>
  2. <head>
  3. <title>TEST</title>
  4.  
  5. <link rel="stylesheet" href="style.css" />
  6. </head>
  7.  
  8. <body>
  9. <div id="header">
  10. <a href="index.php">
  11. <h1>Welcome to the Admin Panel</h1></a>
  12.  
  13. </div>
  14.  
  15. <div id="sidebar">
  16.  
  17. <h2><a href="#">A</a></h2>
  18. <h2><a href="#">B</a></h2>
  19. <h2><a href="#">C</a></h2>
  20. <h2><a href="#">D</a></h2>
  21.  
  22.  
  23. </div>
  24. <?php
  25.  
  26. include("includes/connect.php");
  27.  
  28. if(isset($_GET['edit'])){
  29.  
  30. $edit_id = $_GET['edit'];
  31.  
  32. $edit_query = "select * from posts where post_id='$edit_id'";
  33.  
  34. $run_edit = mysql_query($edit_query);
  35.  
  36. while ($edit_row=mysql_fetch_array($run_edit)){
  37.  
  38.  
  39. $post_id = $edit_row['post_id'];
  40. $post_title = $edit_row['post_title'];
  41. $post_author = $edit_row['post_author'];
  42. $post_keywords = $edit_row['post_keywords'];
  43. $post_image = $edit_row['post_image'];
  44. $post_content = $edit_row['post_content'];
  45. }
  46. }
  47. ?>
  48.  
  49. <form method="post" action="edit_posts.php?edit_form=<?php echo $edit_id; ?>" enctype="multipart/form-data">
  50.  
  51. <table width="600" bgcolor="orange" align="center" border="10">
  52.  
  53. <tr>
  54. <td align="center" bgcolor="yellow" colspan="6"><h1>Edit The Post Here</h1></td>
  55. </tr>
  56.  
  57. <tr>
  58. <td align="right">Post Title:</td>
  59. <td><input type="text" name="title" size="30" value="<?php echo $post_title; ?>"></td>
  60. </tr>
  61.  
  62. <tr>
  63. <td align="right">Post Author:</td>
  64. <td><input type="text" name="author" size="30"value="<?php echo $post_author; ?>"></td>
  65. </tr>
  66.  
  67. <tr>
  68. <td align="right">Post Keywords:</td>
  69. <td><input type="text" name="keywords" size="30"value="<?php echo $post_keywords; ?>"></td>
  70. </tr>
  71.  
  72. <tr>
  73. <td align="right">Post Image:</td>
  74. <td>
  75. <input type="file" name="image">
  76. <img src="../images/<?php echo $post_image;?>" width="100" height="100"></td>
  77. </tr>
  78.  
  79. <tr>
  80. <td align="right">Post Content:</td>
  81. <td><textarea name="content" cols="30" rows="15"><?php echo $post_content; ?></textarea></td>
  82. </tr>
  83.  
  84. <tr>
  85. <td align="center" colspan="6"><input type="submit" name="update" value="Update Now"></td>
  86. </tr>
  87. </table>
  88.  
  89. </form>
  90. </body>
  91. </html>
  92. <?php
  93.  
  94. if(isset($_POST['update'])){
  95.  
  96. $update_id = $_GET['edit_form'];
  97. $post_title1 = $_POST['title'];
  98. $post_date1 = date('m-d-y');
  99. $post_author1 = $_POST['author'];
  100. $post_keywords1 = $_POST['keywords'];
  101. $post_content1 = $_POST['content'];
  102. $post_image1= $_FILES['image']['name'];
  103. $image_tmp= $_FILES['image']['tmp_name'];
  104.  
  105. if($post_title1=='' or $post_author1=='' or $post_keywords1=='' or $post_content1=='' or $post_image1==''){
  106.  
  107. echo "<script>alert('Any of the fields is empty')</script>";
  108. exit();
  109. }
  110.  
  111. else {
  112.  
  113. move_uploaded_file($image_tmp,"../images/$post_image1");
  114.  
  115. $update_query = "update posts set post_title='$post_title1',post_date='$post_date1',post_author='$post_author1',post_image='$post_image1',post_keywords='$post_keywords1',post_content='$post_content1' where post_id='$update_id'";
  116.  
  117. if(mysql_query($update_query)){
  118.  
  119. echo "<script>alert('Post has been updated')</script>";
  120.  
  121. echo "<script>window.open('view_posts.php','_self')</script>";
  122.  
  123. }
  124.  
  125. }
  126. }
  127.  
  128.  
  129.  
  130. ?>


Po naciśnięciu przycisku "Post has been updated" wyrzuca mi błąd:
"Any of the fields is empty"

a w polach:
Post Title <- <br /><b>Notice</b>: Undefined variable: post_title in <b>C:\xamp\htdocs\test\test\edit_posts.php</b> on line <b>59</b><br />
Post Author <- <br /><b>Notice</b>: Undefined variable: post_author in <b>C:\xamp\htdocs\test\test\edit_posts.php</b> on line <b>64</b><br />
Post Keywords <- <br /><b>Notice</b>: Undefined variable: post_keywords in <b>C:\xamp\htdocs\test\test\edit_posts.php</b> on line <b>69</b><br />
Post Image <- nie ładuje obrazka
Post Content: <- <br />
<b>Notice</b>: Undefined variable: post_content in <b>C:\xamp\htdocs\test\test\edit_posts.php</b> on line <b>81</b><br />




Gdzie może być błąd ?
johny_s
przerzuć obsługę posta nad formularz i poczytaj o sql injection
ayo1001
Okej, ale gdzie jest błąd ?
markuz
Błąd polega na tym, że próbujesz wyświetlić zmienną która nie istnieje np. $post_title
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.