Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. <?php
  2.  
  3. $hostname = 'localhost';
  4. $username = '';
  5. $password = '';
  6.  
  7. $database = '';
  8.  
  9. $con = mysql_connect($hostname, $username, $password) or die(mysql_error()); // I would avoid using or dies for MySQL, but that's just me.
  10.  
  11. mysql_select_db($database) or die(mysql_error());
  12.  
  13.  
  14. // We need to sanitize the user input.
  15. // First mysql_real_escape_string makes sure nothing "unexpected" is going in MySQL.
  16. // htmlspecialchars removes any HTML formatting that is not needed.
  17. $name = mysql_real_escape_string(htmlspecialchars($_POST['name']));
  18. $body = mysql_real_escape_string(htmlspecialchars($_POST['body']));
  19.  
  20. $query = mysql_query("INSERT INTO blog (name, body) VALUES('$name', '$body')");
  21.  
  22. if($query == true) {
  23.     echo '1 record was added!';
  24. } else {
  25.     die(mysql_error());
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement