0

Currently, I am trying to work on adding a webpage on Amazon Web Services. The web page contains PHP and HTML code intended to display a particular table from my local MySQL database. I have already created an EC2 instance and a AWS RDS instance, however, there is a problem that is happening consistently which is bothering me. On my computer's local host through MySQL, the code to display all records of a table was this:

SELECT * from Students, StudentProfile, Job 
WHERE Students.StudentID=StudentProfile.Students_StudentID and Students.StudentID=Job.Students_StudentID;

Based from the above code, this executes perfectly and I did confirmed this by doing the same procedure at the MySQL Workbench. However, upon uploading my file called "projectview.php" (the .php file to view all records of a table) onto AWS, it doesn't work. I was aware that I knew I had to change parts of my code for connecting it to AWS's RDS instance. As a result, I followed the tutorial example in creating a sample page based from a tutorial in AWS. Below of this contains a sample .php file that contains my current work for a website to display.

<HTML>
<HEAD>   
<TITLE>List Students</title>
<link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">
<style>
  body {font-family: 'Varela Round', sans-serif;
  background-color: #ffddcc;
  color: #e64d00;
  border: 2px solid #ff7733;
  border-radius: 10px;
 }

 h1 {font-family: Georgia, serif;}

 input {color:#e64d00;}

</style>
</head>
<BODY>
 <H1>List Students</h1>  
 <?php include '../inc/dbinfo.inc';  

 $conn = @mysqli_connect("DB_SERVER","DB_USERNAME","DB_PASSWORD","DB_DATABASE" );

 if($conn->connect_error) {
 die("Connection failed:" . $conn->connect_error);
 }

 else
 {
    echo "Status:Connected.";
     echo "<br>";
  }

  $sql = "SELECT * from Students, StudentProfile, Job 
  where Students.StudentID=StudentProfile.Students_StudentID and Students.StudentID=Job.Students_StudentID";
   mysql_select_db("project2");
   $result = mysqli_query($conn, $sql);

   if(!$result) {
   die('Could not get data: ' .mysql_error());
   }
   while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "<br>";
    echo "StudentID: " . $row["studentID"]. "<br>";
    echo "First Name: " . $row["firstName"]. "<br>";
    echo "Last Name: " . $row["lastName"]. "<br>";
    echo "Major: " . $row["Major"]. "<br>";
    echo "Level: " . $row["Level"]. "<br>";
    echo "Address: " . $row["Address"]. "<br>";
    echo "City: " . $row["City"]. "<br>";
    echo "Country: " . $row["Country"]. "<br>";
    echo "Zipcode: " . $row["Zipcode"]. "<br>";
    echo "Phone: " . $row["Phone"]. "<br>";
    echo "Job Company: " . $row["Job_Company"]. "<br>";
    echo "Job Title: " . $row["Job_Title"]. "<br>";
     }

     echo "Fetched data successfully\n";
     //$result = $conn->query($query);


     $conn->close();
     ?>
     <br>
     <FORM METHOD="LINK" ACTION="project2mainmenu.html">
     <INPUT TYPE="submit" VALUE="Return to Main Menu">
     </form>
     </body>
     </html>

Furthermore, I noticed that when I check at my web page after running the code, it shows an image like this: Photo

****Note: I already uploaded all my related files for the particular web pages. Also, this web page is not affiliated with any other files. It is a stand-alone file.**

PravinS
  • 2,640
  • 3
  • 21
  • 25
LSRain
  • 103
  • 1
  • 14
  • You are mixing mysql_*() and mysql**I**_*() function calls. They belong to two different APIs. Use mysqli :) – Shadow Mar 24 '17 at 10:02
  • I see. Well, it turns out that I changed mysql statements into mysqli and it works. However, there is still a problem that the query that I written doesn't execute. I'm wondering if it is related to the connection. – LSRain Mar 24 '17 at 17:48

1 Answers1

-1

Apply this code and set your query it's working fine. i have create connection from new mysqli. it's result like this http://prntscr.com/envt1l

<HTML>
<HEAD>  
<TITLE>List Students</title>
<link href="https://fonts.googleapis.com/css?family=Varela+Round" rel="stylesheet">
<style>
body {font-family: 'Varela Round', sans-serif;
background-color: #ffddcc;
color: #e64d00;
border: 2px solid #ff7733;
border-radius: 10px;
}
h1 {font-family: Georgia, serif;}
input {color:#e64d00;}
</style>
  </head>
<BODY>
<H1>List Students</h1>
<?php //include '../inc/dbinfo.inc';
$conn = new mysqli('localhost','root','','wordpress1');
if($conn->connect_error) {
die("Connection failed:" . $conn->connect_error);
}
else
{
  echo "Status:Connected.";
   echo "<br>";
}
$sql = "SELECT * from wp_terms";
//mysql_select_db("project2");
$result = mysqli_query($conn, $sql);
if(!$result) {
die('Could not get data: ' .mysql_error());
}
foreach ($result as $value) {
  echo "<br>";
  echo "term_id: " . $value["term_id"]. "<br>";
  echo "name: " . $value["name"]. "<br>";
  echo "slug: " . $value["slug"]. "<br>";
}
 echo "Fetched data successfully\n";
 //$result = $conn->query($query);


 $conn->close();
 ?>
 <br>
 <FORM METHOD="LINK" ACTION="project2mainmenu.html">
 <INPUT TYPE="submit" VALUE="Return to Main Menu">
 </form>
 </body>
 </html>