Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/T

ID: 3915620 • Letter: #

Question

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Available Opportunities</title>
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />

</head>
<body>

<h1>College Internships</h1>
<h2>Available Opportunities</h2>

<?php

if (isset($_REQUEST['internID']))     
$InternID = $_REQUEST['internID'];
else     
$InternID = ?1;

$errors = 0;
$DBConnect = @mysql_connect("localhost", "root", "");
if ($DBConnect === FALSE) {     
echo "<p>Unable to connect to the database server. " .         
  "Error code " . mysql_errno() . ": " .         
  mysql_error() . "</p> ";    
++$errors;
}
else {    
$DBName = "internships";    
$result = @mysql_select_db($DBName,     
$DBConnect);     if ($result === FALSE) {         
  echo "<p>Unable to select the database. " .              
   "Error code " . mysql_errno($DBConnect) . ": " .              
   mysql_error($DBConnect) . "</p> ";         
  ++$errors;    
}
}

$TableName = "interns";
if ($errors == 0) {    
$SQLstring = "SELECT * FROM $TableName WHERE " .              
  " internID='$InternID'";    
$QueryResult = @mysql_query($SQLstring, $DBConnect);    
if ($QueryResult === FALSE) {         
  echo "<p>Unable to execute the query. " .              
   "Error code " . mysql_errno($DBConnect) . ": " .              
   mysql_error($DBConnect) . "</p> ";         
  ++$errors;    
}    
else {         
  if (mysql_num_rows($QueryResult) == 0) {              
   echo "<p>Invalid Intern ID!</p>";              
   ++$errors;         
  }    
}
}

if ($errors == 0) {     
$Row = mysql_fetch_assoc($QueryResult);     
$InternName = $Row['first'] . " " . $Row['last'];
} else     
$InternName = "";

$TableName = "assigned_opportunities";
$ApprovedOpportunities = 0;
$SQLstring = "SELECT COUNT(opportunityID) FROM
$TableName " .         
   " WHERE internID='$InternID' " .         
   " AND date_approved IS NOT NULL";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if (mysql_num_rows($QueryResult) > 0) {    
$Row = mysql_fetch_row($QueryResult);    
$ApprovedOpportunities = $Row[0];   
mysql_free_result($QueryResult);
}

$SelectedOpportunities = array();
$SQLstring = "SELECT opportunityID FROM $TableName " .         
  " WHERE internID='$InternID'";
$QueryResult = @mysql_query($SQLstring, $DBConnect);
if (mysql_num_rows($QueryResult) > 0) {    
while (($Row = mysql_fetch_row($QueryResult))    
!== FALSE)         
  $SelectedOpportunities[] = $Row[0];    
mysql_free_result($QueryResult);
}

$AssignedOpportunities = array();
$SQLstring = "SELECT opportunityID FROM $TableName " .         
   " WHERE date_approved IS NOT NULL";
$QueryResult = @mysql_query($SQLstring,$DBConnect);
if (mysql_num_rows($QueryResult) > 0) {    
while (($Row = mysql_fetch_row($QueryResult)) !== FALSE)         
  $AssignedOpportunities[] = $Row[0];    
mysql_free_result($QueryResult);
}

$TableName = "opportunities";
$Opportunities = array();
$SQLstring = "SELECT opportunityID, company, city, " .         
   " start_date, end_date, position, description FROM $TableName";
$QueryResult = @mysql_query($SQLstring,$DBConnect);
if (mysql_num_rows($QueryResult) > 0) {    (line105)
while (($Row = mysql_fetch_assoc($QueryResult)) !== FALSE)         
  $Opportunities[] = $Row;         
  mysql_free_result($QueryResult);
}
mysql_close($DBConnect);

echo "<table border='1' width='100%'> ";
echo "<tr> ";
echo "    <th>Company</
th> ";
echo "    <th>City</th> ";
echo "    <th>Start
Date</th> ";
echo "    <th>End
Date</th> ";
echo "    <th>Position</ th> ";
echo "    <th>Description</
th> ";
echo "    <th>Status</
th> ";
echo "</tr> ";
foreach ($Opportunities as $Opportunity) {   
if (!in_array($Opportunity['opportunityID'],           
   $AssignedOpportunities)) {       
  echo "<tr> ";       
  echo "    <td>" .               
    htmlentities($Opportunity['company']) .               
    "</td> ";       
  echo "    <td>" .               
    htmlentities($Opportunity['city']) .               
    "</td> ";       
  echo "    <td>" .               
    htmlentities($Opportunity               
    ['start_date']) .               
    "</td> ";     
  echo "    <td>" .               
    htmlentities($Opportunity['end_date']) .               
    "</td> ";      
  echo "    <td>" .               
    htmlentities($Opportunity['position']) .               
    "</td> ";       
  echo "    <td>" .               
    htmlentities($Opportunity              
    ['description']) .               
    "</td> ";       
  echo "    <td>";       
  if (in_array($Opportunity['opportunityID'],               
    $SelectedOpportunities))           
   echo "Selected";       
  else {           
   if ($ApprovedOpportunities>0)               
    echo "Open";           
   else               
    echo "<a href="RequestOpportunity.php?" .                   <br/>      "internID=$InternID&amp;" .                   <br/>      "opportunityID=" . $Opportunity["opportunityID'] .                   
     "'>Available</a>";       
  }       
  echo "</td> ";       
  echo "</tr> ";   
}
}
echo "</table> ";
echo "<p><a href="InternLogin.php">Log Out</a></
p> ";

?>

</body>
</html>


Will someone please help me understand why i receive this message?

<< Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:wampwwwPHP_ProjectsPHP_ProjectsPHP_ProjectsChapter.09ChapterAvailableOpportunities.php on line 105 >>

Thanks!

Explanation / Answer

It means QueryResult raises error....

$SQLstring = "SELECT opportunityID, company, city, " .         
   " start_date, end_date, position, description FROM $TableName";

description column is predefined keyword in mysql, so we can't use it directly like that...

change like this...

$SQLstring = "SELECT opportunityID, company, city, " .         
   " start_date, end_date, position, `description` FROM $TableName";

Let me know if you have any doubts, please give me comment...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote