Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. include 'ConnectPicture.php';
  3.  
  4. $showtables = "SELECT COUNT(*) FROM picturetable";
  5. $tableexists = mysqli_query($connectedToDatabasePicture, $showtables);
  6. $hello = 1;
  7. if(!$tableexists){
  8.  
  9. displaynoPictureText();
  10.  
  11. }else{
  12.  
  13. displayPicture();
  14.  
  15. }
  16.  
  17. function displayPicture(){
  18. global $connectedToDatabasePicture;
  19. $getpicture = "SELECT * FROM picturetable ORDER BY cid DESC";
  20.  
  21. $result = mysqli_query($connectedToDatabasePicture, $getpicture);
  22. // While a row of data exists, put that row in $row as an associative array
  23. echo $result;
  24. while($row = mysqli_fetch_assoc($result)){
  25. $filepath = $row['path'].$row['picturename'];
  26. echo "<img src=$filepath style="width:100%">";
  27. echo $row['textarea'];
  28. }
  29. }
  30.  
  31. function displaynoPictureText(){
  32.  
  33. echo"NO PICTURE TO DISPLAY";
  34.  
  35. }
  36.  
  37.  
  38.  
  39. ?>
  40.  
  41. <?php
  42. //Servername
  43. $mysql_servername = 'localhost';
  44. //Username for the database
  45. $mysql_user = 'root';
  46. //Password for the database
  47. $mysql_password = '7JwHEHVS4haREdWB';
  48.  
  49. //Needs to run a connection to a database. The information about which database to connect to should be inserted into the paranthesis.
  50. //Servername, username for the database, and the password for the database.
  51. $connectedToDatabaseComments = mysqli_connect($mysql_servername,$mysql_user,$mysql_password);
  52.  
  53. //If there is no connection, go inside the first if
  54. if (!$connectedToDatabaseComments)
  55. {
  56. //Die function, which kills the connection
  57. die("Database connection failed: " . mysqli_connect_error());
  58. }else
  59. {
  60. //Else go inside here
  61. //Select the database in the second parameter from connection in the first parameter
  62. //It returns true or false based on if the database could be selected
  63. $databaseSelectedComments = mysqli_select_db($connectedToDatabaseComments,"blogdatabase");
  64.  
  65. //If the database can not be selected go to the if
  66. if(!$databaseSelectedComments)
  67. {
  68. //Print database connection failed
  69. echo "Database connection failed";
  70. }
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement