Advertisement
Guest User

Untitled

a guest
Jan 17th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2. $mysql_server = "*********"; //This is probably correct
  3. $mysql_username = "*********";    // Your MySQL username
  4. $mysql_password = "*********";        // Your MySQL Password
  5. $mysql_database = "*********";     // The name of your database
  6. $mysql_table = "*********"; // Your actual table to hold the data
  7.  
  8. // Make a MySQL Connection no changes need to be made here
  9. $con = mysql_connect($mysql_server,$mysql_username,$mysql_password) or die('Can not connect to server');
  10. mysql_select_db($mysql_database) or die('Can not connect to database');
  11.  
  12. /*
  13. Variables passed from URL - list them all here.
  14. */
  15. $f = $_GET['f'];
  16. $p_date = mysql_real_escape_string($_GET['date']);
  17. $p_snick = mysql_real_escape_string($_GET['snick']);
  18. $p_smail =  mysql_real_escape_string($_GET['smail']);
  19. $p_tnick =  mysql_real_escape_string($_GET['tnick']);
  20. $p_tmail =  mysql_real_escape_string($_GET['tmail']);
  21. $p_message =  mysql_real_escape_string($_GET['message']);
  22.  
  23.  
  24.  
  25. //This function will save text to database
  26. function create_account($con, $mysql_table, $p_date, $p_snick, $p_smail, $p_tnick, $p_tmail,$p_message)  //declare function Part between () is all the variables you will need for this function.
  27. {
  28.    
  29.     mysql_query("INSERT INTO $mysql_table (p_date, p_snick, p_smail, p_tnick, p_tmail, p_message) VALUES('$p_date','$p_snick','$p_smail','$p_tnick','$p_tmail','$p_message')")
  30.     or die('0'); // Something went wrong
  31.  
  32.     echo "1"; //All is right with the world. YAY.
  33.     mysql_close($con);
  34. }
  35.  
  36. // This function is used for nothing more than testing that the script and database are working.
  37. function connection_test($con, $mysql_table, $p_snick)
  38. {
  39.     $result = mysql_query("SELECT * FROM $mysql_table WHERE snick = '$p_snick' ");
  40.     while($row = mysql_fetch_array($result))
  41.     if ($row <= 0)
  42.         {
  43.         echo "Could not comunicate with database. Double check your settings and ask your web host for help.";
  44.         }
  45.     else
  46.         {
  47.         echo "Connection test was OK!";
  48.         }
  49.     }
  50.  
  51. // This determines which function to call based on the $f parameter passed in the URL.
  52. switch($f)
  53. {
  54.     case na: create_account($con, $mysql_table, $p_date, $p_snick, $p_smail, $p_tnick, $p_tmail,$p_message); break;
  55.     case ts: connection_test($con, $mysql_table, $p_snick); break;
  56.     case ct: echo"1";
  57.     default: echo"error";
  58. }
  59.  
  60. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement