Advertisement
tnngo2

PHP - Theory 2 - Demo 1 - php

Mar 12th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. <!DOCTYPE html public "-//W3C//DTD HTML 4.0 //EN">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>Databases and Webprogramming: Assignment 4.1</title>
  6. </head>
  7. <body bgcolor="#f9f9f9">
  8.  
  9. <?php
  10.  
  11. // Read the name using either the $_GET or the $_POST variable
  12.  
  13. $first_name = $_POST['first_name'] ;
  14. $last_name = $_POST['last_name'] ;
  15. $age = $_POST['age'] ;
  16.  
  17. $con = mysqli_connect("localhost","root","","my_db")
  18. or die('Could not connect: ' . mysql_error());
  19.  
  20. $query = "INSERT INTO student VALUES (\"" . $first_name . "\",\"" . $last_name . "\",\"" . $age . "\")";
  21.  
  22. $result = mysqli_query($con, $query)
  23. or die('Error insert database.');
  24.  
  25. echo "added";
  26.  
  27. mysqli_close($con);
  28.  
  29.  
  30. ?>
  31.  
  32. </p>
  33. </form>
  34.  
  35. </body>
  36. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement