Anyone knows what I'm doing wrong here? I am getting supplied argument is not a valid MySQL result resource in line 34

<?php
//Connect to database server
$conn=mysql_connect("mywebsite", "user", "pass");
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("data", $conn);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>gg</title>
</head>
<body>

<?php

$result= mysql_query("SELECT student.First_Name AS first,
                          student.Last_Name AS last,
	     	          faculty.First_Name AS afirst,
                          faculty.Last_Name AS alast,
                          faculty.Office AS office,
	     	          faculty.Phone AS phone
                          FROM Student
	                  INNER JOIN Faculty
	                  ON Student.Advisor_ID=Faculty.Faculty_ID
                          ORDER BY last, first, afirst, alast, office, phone;");
	  
if (!$result) {

      die('Invalid query: ' . mysql_error());

      }

   while ($row = mysql_fetch_array($result)) {
	  
	  echo '<h2>Students and Advisors</h2>';
	  echo '<table width="100%" border="2">';
 	  echo '<tr>';
          echo '<th>Student First Name</th>';
          echo '<th>Student Last Name</th>';
          echo '<th>Student Advisors First Name</th>';
          echo '<th>Student Advisors Last Name</th>';
	  echo '<th>Advisor Office</th>';
	  echo '<th>Advisor Phone</th>';
 	  echo '</tr>';
	  echo '<tr>';
	  echo "<td>".$row['first']."</td>";
	  echo "<td>".$row['last']."</td>";
	  echo "<td>".$row['afirst']."</td>";
	  echo "<td>".$row['alast']."</td>";
	  echo "<td>".$row['office']."</td>";
	  echo "<td>".$row['phone']."</td>";
	  echo '</tr>';
	  echo '</table>';
	  }
	  mysql_close($conn);		  	  
?>
</body>
</html>

Your query is failing. Try placing this after your query call

if (!$result) {
    die('Invalid query: ' . mysql_error());
}

It says "Invalid query: Table 'data' doesn't exist"
Is that mean it can't find my databasE?

Not necessarily the problem but this code

if (!$conn)
{
  die('Could not connect: ' . mysql_error());
}

Should be moved to line 4.

I updated the post, the same result as before "Invalid query: Table 'data' doesn't exist

Interesting because I don't see anywhere in your code where you're querying a 'data' table. If it couldn't find the database it would give you Unknown database 'data' not Table 'data' doesn't exist .

Is that all of the code or is that just a bit of it? Also, repost your code with the changes.

This code is all of it I didnt change anything besides user, pass, data, and website.
I have rechecked my codes but I can't seem to find what I did wrong.

<?php
//Connect to database server
$conn=mysql_connect("website", "user", "pass");
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("data", $conn);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>gg</title>
</head>
<body>

<?php

$result= mysql_query("SELECT student.First_Name AS first,
             student.Last_Name AS last,
	     	 faculty.First_Name AS afirst,
             faculty.Last_Name AS alast,
             faculty.Office AS office,
	     	 faculty.Phone AS phone
      FROM Student
	  INNER JOIN Faculty
	  ON Student.Advisor_ID=Faculty.Faculty_ID
      ORDER BY last, first, afirst, alast, office, phone;");
	  

      if (!$result) {

      die('Invalid query: ' . mysql_error());

      }
   while ($row = mysql_fetch_array($result)) {
	  
	  echo '<h2>Students and Advisors</h2>';
	  echo '<table width="100%" border="2">';
 	  echo '<tr>';
      echo '<th>Student First Name</th>';
      echo '<th>Student Last Name</th>';
      echo '<th>Student Advisors First Name</th>';
      echo '<th>Student Advisors Last Name</th>';
	  echo '<th>Advisor Office</th>';
	  echo '<th>Advisor Phone</th>';
 	  echo '</tr>';
	  echo '<tr>';
	  echo "<td>".$row['first']."</td>";
	  echo "<td>".$row['last']."</td>";
	  echo "<td>".$row['afirst']."</td>";
	  echo "<td>".$row['alast']."</td>";
	  echo "<td>".$row['office']."</td>";
	  echo "<td>".$row['phone']."</td>";
	  echo '</tr>';
	  echo '</table>';
	  }
	  mysql_close($conn);		  	  
?>
</body>
</html>

K, last addition, if this doesn't give us something then I'm fresh out of ideas. replace mysql_select_db() with

$dbselect = mysql_select_db('data', $conn);
if(!$dbselect) {
  die('Couldn\'t use database: ' . mysql_error());
}

Still the same thing "Invalid query: Table 'data.Student' doesn't exist"
well I left out ".Student" before see if that helps

<?php
//Connect to database server
$conn=mysql_connect("website", "user", "pass");
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
$dbselect = mysql_select_db('data', $conn);
if(!$dbselect) {
 die('Could not find data: ' . mysql_error());
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Students and Advisors</title>
</head>
<body>

<?php

$result= mysql_query("SELECT student.First_Name AS first,
             student.Last_Name AS last,
	     	 faculty.First_Name AS afirst,
             faculty.Last_Name AS alast,
             faculty.Office AS office,
	     	 faculty.Phone AS phone
      FROM Student
	  INNER JOIN Faculty
	  ON Student.Advisor_ID=Faculty.Faculty_ID
      ORDER BY last, first, afirst, alast, office, phone;");
	  

      if (!$result) {

      die('Invalid query: ' . mysql_error());

      }
   while ($row = mysql_fetch_array($result)) {
	  
	  echo '<h2>Students and Advisors</h2>';
	  echo '<table width="100%" border="2">';
 	  echo '<tr>';
      echo '<th>Student First Name</th>';
      echo '<th>Student Last Name</th>';
      echo '<th>Student Advisors First Name</th>';
      echo '<th>Student Advisors Last Name</th>';
	  echo '<th>Advisor Office</th>';
	  echo '<th>Advisor Phone</th>';
 	  echo '</tr>';
	  echo '<tr>';
	  echo "<td>".$row['first']."</td>";
	  echo "<td>".$row['last']."</td>";
	  echo "<td>".$row['afirst']."</td>";
	  echo "<td>".$row['alast']."</td>";
	  echo "<td>".$row['office']."</td>";
	  echo "<td>".$row['phone']."</td>";
	  echo '</tr>';
	  echo '</table>';
	  }
	  mysql_close($conn);		  	  
?>
</body>
</html>

well yeah, the fact that you left out that it said data.Student is pretty big :) lowercase Student on line 32 , case is important, that should fix it

commented: Thank You +1

hahaha, Wupee that works! :D Thank you !!

One silly question how do you repeat the table ("<td></td>") as long as the statement is true because my other data wasn't inside the table

<?php
//Connect to database server
$conn=mysql_connect("website", "user", "password");
if (!$conn)
  {
  die('Could not connect: ' . mysql_error());
  }
$dbselect = mysql_select_db('data', $conn);
if(!$dbselect) {
 die('Could not find data: ' . mysql_error());
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Students and Advisors</title>
</head>
<body>
<h2>Students and Advisors</h2>
<table width="100%" border="2">
<tr>
<th>Student First Name</th>
<th>Student Last Name</th>
<th>Student Advisors First Name</th>
<th>Student Advisors Last Name</th>
<th>Advisor Office</th>
<th>Advisor Phone</th>
</tr>

<?php
	  
$result= mysql_query("SELECT student.First_Name AS first,
             student.Last_Name AS last,
	     	 faculty.First_Name AS afirst,
             faculty.Last_Name AS alast,
             faculty.Office AS office,
	     	 faculty.Phone AS phone
      FROM student
	  INNER JOIN faculty
	  ON student.Advisor_ID=faculty.Faculty_ID
      ORDER BY last, first, afirst, alast, office, phone;");
	  

      if (!$result) {

      die('Invalid query: ' . mysql_error());

      }
	  	  
while ($row = mysql_fetch_array($result)) {
	  
	 
	  echo '<tr>';
	  echo "<td>".$row['first']."</td>";
	  echo "<td>".$row['last']."</td>";
	  echo "<td>".$row['afirst']."</td>";
	  echo "<td>".$row['alast']."</td>";
	  echo "<td>".$row['office']."</td>";
	  echo "<td>".$row['phone']."</td>";
	  echo '</tr>';
	  echo '</table>';
	  }
	  mysql_close($conn);		  	  
?>
</body>
</html>

move the echo '</table>'; outside the loop. or just put </table> before </body> and remove the echo altogether

Oh right right thanks again :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.