Guest User

Untitled

a guest
Jan 13th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.07 KB | None | 0 0
  1. Updating MySQL using a form my code is not working
  2. <?php
  3. $host=""; // Host name
  4. $username=""; // Mysql username
  5. $password=""; // Mysql password
  6. $db_name=""; // Database name
  7. $tbl_name=""; // Table name
  8.  
  9. // Connect to server and select database.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // get value of id that sent from address bar
  14. $dj=$_GET['dj'];
  15.  
  16. // Retrieve data from database
  17. $sql="SELECT * FROM $tbl_name WHERE dj='$dj'";
  18. $result=mysql_query($sql);
  19. $rows=mysql_fetch_array($result);
  20. ?>
  21.  
  22. <table width="400" border="0" cellspacing="1" cellpadding="0">
  23. <tr>
  24. <form name="form1" method="post" action="update_ac.php">
  25. <td>
  26. <table width="100%" border="0" cellspacing="1" cellpadding="0">
  27. <tr>
  28. <td>&nbsp;</td>
  29. <td colspan="3"><strong>Update The information for the Now PlayingProgram.</strong>
  30. </td>
  31. </tr>
  32. <tr>
  33. <td align="center">&nbsp;</td>
  34. <td align="center">&nbsp;</td>
  35. <td align="center">&nbsp;</td>
  36. <td align="center">&nbsp;</td>
  37. </tr>
  38. <tr>
  39. <td align="center">&nbsp;</td>
  40. <td align="center"><strong>Name</strong></td>
  41. <td align="center"><strong>Email</strong></td>
  42. <td align="center"><strong>Email2</strong></td>
  43. </tr>
  44. <tr>
  45. <td>&nbsp;</td>
  46. <td align="center">
  47. <input name="name" type="text" id="name" value="<?php echo $rows['name']; ?>">
  48. </td>
  49. <td align="center">
  50. <input name="email" type="text" id="email" value="<?php echo $rows['email']; ?>" size="15">
  51. </td>
  52. <td>
  53. <input name="email2" type="text" id="email2" value="<?php echo $rows['email2']; ?>" size="15">
  54. </td>
  55. </tr>
  56. <tr>
  57. <td align="center">&nbsp;</td>
  58. <td align="center"><strong>Twitter</strong></td>
  59. <td align="center"><strong>Twitter2</strong></td>
  60. <td align="center"><strong>Avatar</strong></td>
  61. </tr>
  62. <tr>
  63. <td>&nbsp;</td>
  64. <td align="center">
  65. <input name="twitter" type="text" id="twitter" value="<?php echo $rows['twitter']; ?>">
  66. </td>
  67. <td align="center">
  68. <input name="twitter2" type="text" id="twitter2" value="<?php echo $rows['twitter2']; ?>" size="15">
  69. </td>
  70. <td>
  71. <input name="avatar" type="text" id="avatar" value="<?php echo $rows['avatar']; ?>" size="15">
  72. </td>
  73. </tr>
  74. <tr>
  75. <td align="center">&nbsp;</td>
  76. <td align="center"><strong>Facebook</strong></td>
  77. <td align="center"><strong>Facebook2</strong></td>
  78. <td align="center"><strong>Type</strong></td>
  79. </tr>
  80. <tr>
  81. <td>&nbsp;</td>
  82. <td align="center">
  83. <input name="facebook" type="text" id="facebook" value="<?php echo $rows['facebook']; ?>">
  84. </td>
  85. <td align="center">
  86. <input name="facebook2" type="text" id="facebook2" value="<?php echo $rows['facebook2']; ?>" size="15">
  87. </td>
  88. <td>
  89. <input name="type" type="text" id="type" value="<?php echo $rows['type']; ?>" size="15">
  90. </td>
  91. </tr>
  92. <tr>
  93. <td align="center">&nbsp;</td>
  94. <td align="center"><strong>Alias1</strong></td>
  95. <td align="center"><strong>Alias2</strong></td>
  96. <td align="center"><strong>Alias3</strong></td>
  97. </tr>
  98. <tr>
  99. <td>&nbsp;</td>
  100. <td align="center">
  101. <input name="alias1" type="text" id="alias1" value="<?php echo $rows['alias1']; ?>">
  102. </td>
  103. <td align="center">
  104. <input name="alias2" type="text" id="alias2" value="<?php echo $rows['alias2']; ?>" size="15">
  105. </td>
  106. <td>
  107. <input name="alias3" type="text" id="alias3" value="<?php echo $rows['alias3']; ?>" size="15">
  108. </td>
  109. </tr>
  110.  
  111. <tr>
  112. <td align="center">&nbsp;</td>
  113. <td colspan="3" align="center"><strong>Request Line</strong></td>
  114. </tr>
  115. <tr>
  116. <td>&nbsp;</td>
  117. <td colspan="3" align="center">
  118. <input name="address" type="text" id="address" value="<?php echo $rows['address']; ?>" size="65">
  119. </td>
  120. </tr>
  121. <tr>
  122. <td>&nbsp;</td>
  123. <td>
  124. <input name="dj" type="hidden" id="dj" value="<?php echo $rows['dj']; ?>">
  125. </td>
  126. <td align="center">
  127. <input type="submit" name="Submit" value="Submit">
  128. </td>
  129. <td>&nbsp;</td>
  130. </tr>
  131. </table>
  132. </td>
  133. </form>
  134. </tr>
  135. </table>
  136. <?php
  137. // close connection
  138. mysql_close();
  139. ?>
  140.  
  141. <?php
  142. $host="localhost"; // Host name
  143. $username=""; // Mysql username
  144. $password=""; // Mysql password
  145. $db_name=""; // Database name
  146. $tbl_name=""; // Table name
  147.  
  148. // Connect to server and select database.
  149. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  150. mysql_select_db("$db_name")or die("cannot select DB");
  151.  
  152. // Connect to server and select database.
  153. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  154. mysql_select_db("$db_name")or die("cannot select DB");
  155.  
  156. // update data in mysql database
  157. $sql="UPDATE currentdj SET name='$name',
  158. email='$email',
  159. email2='$email2',
  160. twitter='$twitter',
  161. twitter2='$twitter2',
  162. avatar='$avatar',
  163. facebook='$facebook',
  164. facebook2='$facebook2',
  165. type='$type',
  166. alias1='$alias1',
  167. alias2='$alias2',
  168. alias3='$alias3',
  169. address='$address'
  170. WHERE dj='$dj'";
  171. $result=mysql_query($sql);
  172.  
  173. // if successfully updated.
  174. if($result){
  175. echo "Successful";
  176. echo "<BR>";
  177. echo "<a href='list_records.php'>View result</a>";
  178. }
  179.  
  180. else {
  181. echo "ERROR";
  182. }
  183.  
  184. ?>
  185.  
  186. $email=$_POST['email'];
  187. $email2=$_POST['email2'];
  188. $twitter=$_POST['twitter'];
  189.  
  190. "UPDATE currentdj SET name='$name',
  191. email='$email', //Add THE MISSING SINGLE QUOTE HERE
  192. email2='$email2',
  193.  
  194. $sql="UPDATE currentdj SET name='$name',
  195. email='$email',
  196. email2='$email2',
  197. twitter='$twitter',
  198. twitter2='$twitter2',
  199. avatar='$avatar',
  200. facebook='$facebook',
  201. facebook2='$facebook2',
  202. type='$type',
  203. alias1='$alias1',
  204. alias2='$alias2',
  205. alias3='$alias3',
  206. address='$address'
  207. WHERE dj='$dj'";
Add Comment
Please, Sign In to add comment