Advertisement
metalx1000

Add all GET Form Submits to MySQL DataBase

Dec 4th, 2014
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2. include("connect.php");
  3. include('table.php');
  4.  
  5. $_GET = array_map('strip_tags', $_GET);
  6. $_GET = array_map('htmlspecialchars', $_GET);
  7.  
  8. //date format and time zone
  9. date_default_timezone_set('America/New_York');
  10. $date = date('l jS \of F Y h:i:s A');
  11.  
  12. $pid=$_GET['pid'];
  13. $result = mysqli_query($con,"SELECT * FROM $table WHERE pid='$pid' ");
  14.  
  15. if( mysqli_num_rows($result) > 0) {
  16.     print "updating...";
  17. }
  18. else
  19. {
  20.     $sql="INSERT INTO $table (pid) VALUES ('$pid')";
  21.     if (!mysqli_query($con,$sql)) {
  22.       die('Error: ' . mysqli_error($con));
  23.     }
  24.  
  25. }
  26.  
  27.  
  28. foreach($_GET as $key => $value) {
  29.     echo 'Current value in $_GET["' . $key . '"] is : ' . $value . '<br>';
  30.     $entry = mysqli_real_escape_string($con, $value);
  31.     //$sql="UPDATE WHERE pid='$pid' $table ($key) VALUES ('$entry')";
  32.     $sql="UPDATE $table SET $key='$entry' WHERE pid='$pid'";
  33.  
  34.     mysqli_query($con,$sql);
  35.     //if (!mysqli_query($con,$sql)) {
  36.     //  die('Error: ' . mysqli_error($con));
  37.     //}
  38. }
  39.  
  40. $udate = date_create();
  41. $unix_date = date_timestamp_get($udate);
  42. $sql="UPDATE $table SET updated='$unix_date' WHERE pid='$pid'";
  43. mysqli_query($con,$sql);
  44. //if (!mysqli_query($con,$sql)) {
  45. //  die('Error: ' . mysqli_error($con));
  46. //}
  47.  
  48. mysqli_close($con);
  49.  
  50. echo "<br>$date";
  51. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement