ram1234

Creating a table in database using php

Nov 6th, 2017
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. <?php
  2. $servername = "localhost";
  3. $username = "scse";
  4. $password = "scse";
  5.  
  6. //Create connection
  7. $conn = mysqli_connect($servername, $username, $password);
  8.  
  9. // Check connection
  10. if(!$conn)
  11. {
  12. die("Connection failed: " . mysqli_connect_error());
  13. }
  14.  
  15. if(!mysqli_select_db($conn, "scse"))
  16. {
  17. echo "Database not selected";
  18. }
  19.  
  20. // sql to create table
  21. $sql = "CREATE TABLE register (
  22. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  23. Name VARCHAR(30) NOT NULL,
  24. Email VARCHAR(50) NOT NULL,
  25. Website VARCHAR(50) NOT NULL,
  26. Message VARCHAR(50)
  27. )";
  28.  
  29. if (mysqli_query($conn, $sql)) {
  30. echo "Table register created successfully";
  31. } else {
  32. echo "Error creating table: " . mysqli_error($conn);
  33. }
  34. ?>
Add Comment
Please, Sign In to add comment