SaveText.Ru

Без имени
  1. <?PHP
  2. $server = "localhost";
  3. $name_user = "root";
  4. $password_user = "";
  5. $db_user = "testdb";
  6.  
  7. try
  8. {
  9. $conn = new PDO("mysql:host=$sever;dbname=$db_user", $name_user, $password_user);
  10.  
  11. if(empty($_POST['name']))
  12. {
  13. exit("Name");
  14. }
  15. if(empty($_POST['content']))
  16. {
  17. exit("Content");
  18. }
  19.  
  20. $query = "INSERT INTO message VALUES (NULL,:names,NOW())";
  21. $msg = $conn -> prepare($query);
  22.  
  23. $msg -> expecting(['names' => $_POST['name']]);
  24.  
  25. $msg_id = $conn -> lastInsertId();
  26.  
  27. $query = "INSERT INTO message_content VALUES(NULL , :content , :message_id)";
  28. $msg = $conn -> prepare($query);
  29. $msg -> execute (['content' => $_POST['content'],'message_id' => $msg_id]);
  30.  
  31. header("Location:index.php");
  32. }
  33. catch(PDOException $e)
  34. {
  35. echo "Error" . $e -> getMessage();
  36. }
  37. ?>
  38.  

Share with your friends:

Распечатать