Advertisement
Guest User

Untitled

a guest
Mar 11th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'ip_address';
  4. $user = 'user_name';
  5. $password = 'password';
  6.  
  7. $link = mysql_connect($host, $user, $password);
  8.  
  9. $selected = mysql_select_db('db_name', $link);
  10.  
  11. if(!isset($_POST['text-input']))
  12.  
  13. ?>
  14.  
  15. <form method="post">
  16. %slice%
  17. <input type="submit" value="Submit" />
  18. </form>
  19. %[if !edit]%
  20.  
  21. <?php
  22. %[repeat items]%
  23. $form_input%id=repeatIndex% = $_POST['element-%id=repeatIndex%'] ;
  24. %[endrepeat]%
  25.  
  26. $query = 'INSERT INTO `table_name` (%[repeat items]%%[endif]%%html="Edit Me"%%[if !edit]%,%[endrepeat]%) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);';
  27. $query = preg_replace('/,);/',');',$query);
  28. $query = preg_replace('/,) /',')',$query);
  29. mysql_query($query);
  30.  
  31. ?>
  32. %[endif]%
  33.  
  34. <?php
  35. db = new PDO('mysql:host=ip_address;dbname=db_name;', 'user_name', 'password');
  36. ?>
  37. <form method="post">
  38. %slice%
  39. <input type="submit" value="Submit" />
  40. </form>
  41. %[if !edit]%
  42.  
  43. <?php
  44. %[repeat items]%
  45. $form_input%id=repeatIndex% = $_POST['element-%id=repeatIndex%'] ;
  46.  
  47. %[endrepeat]%
  48.  
  49. $query = 'INSERT INTO `table_name` (%[repeat items]%%[endif]%%html="Edit Me"%%[if !edit]%,%[endrepeat]%) VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);';
  50. $query = preg_replace('/,);/',');',$query);
  51. $query = preg_replace('/,) /',')',$query);
  52. mysql_query($query);
  53.  
  54.  
  55. ?>
  56. %[endif]%
  57.  
  58. Warning: mysql_query() [function.mysql-query]: Access denied for user
  59. 'kuler'@'localhost' (using password: NO) in
  60. /home/path_to/index.php on line 125
  61.  
  62. Warning: mysql_query() [function.mysql-query]: A link to the server could not be
  63. established in /home/path_to/index.php on line 125
  64.  
  65. <?php
  66.  
  67. //Connection vars
  68. $host = '%id=server%';
  69. $user = '%id=username%';
  70. $password = '%id=password%';
  71. $databasename = '%id=database%';
  72.  
  73. //This block establishes the connection
  74. try{
  75. //
  76. $connectiondetails = "mysql:host={$host};dbname={$databasename}";
  77. $db = new PDO($connectiondetails , $user , $password);
  78. $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_WARNING);
  79. }
  80. catch (PDOException $e) {
  81. print "Error!: " . $e->getMessage() . "<br/>";
  82. die();
  83. }
  84.  
  85. //Check if all the input fields of the form have been submitted
  86. if(
  87. %[repeat items]%
  88. isset($_POST['element-%id=repeatIndex%'])&&
  89. %[endrepeat]%
  90. (true===true)
  91. ){
  92.  
  93.  
  94. //The variables to read the output
  95. %[repeat items]%
  96. $form_input%id=repeatIndex% = $_POST["element-%id=repeatIndex%"] ;
  97. %[endrepeat]%
  98.  
  99. //DB
  100. global $db; //must set this, otherwise can't access the db
  101. $query = 'INSERT INTO `%id=table%` (%[endif]%%[repeat items]%%html="Edit Me"%%[if !edit]%,%[endif]%%[endrepeat]%%[if !edit]%)%[endif]% %[if !edit]%VALUES (%[repeat items]%"' . $form_input%id=repeatIndex% . '",%[endrepeat]%);';
  102. $query = preg_replace('/,);/',');',$query);
  103. $query = preg_replace('/,) /',')',$query);
  104. $db->query($query);
  105. //[DB]
  106. }
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement