Guest User

Untitled

a guest
Jan 13th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. <?php
  2.  
  3. function db_connect(){
  4.     $connection = mysql_connect("localhost","root","");
  5.    
  6.     if(!$connection){
  7.         echo mysql_error();
  8.         exit;
  9.     }
  10.     if(!$row = mysql_select_db("test")){
  11.         echo mysql_error();
  12.         exit;  
  13.     }
  14.     return $connection;
  15. }
  16.  
  17. function add_post($tresc){
  18.     db_connect();
  19.     $query = sprintf("INSERT INTO posts VALUES (NULL, '".$tresc."')");
  20.     $result = mysql_query($query);
  21.     $row = mysql_fetch_assoc($result);
  22.    
  23.     return $row;
  24. }
  25. add_post('test');
  26. ?>
Add Comment
Please, Sign In to add comment