Jump to content

how to solve this error?


nrsh_ram

Recommended Posts

i have try like this..

 

$cur_login = $_SESSION["username"];
$conn= db_connect();
  
$aa=0;

$query1 = "SELECT mm.mentee, mm.username_mentee, mp.major ".
  "FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".
    "ON mp.mentee_id = mm.username_mentee".
         "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee";   
  

$result = $conn->query($query1);
  

 

    <?php
                while ($row = mysqli_fetch_assoc($result)){
                $aa = $aa + 1;
                ?> 
            <td><?php echo $aa; ?> </td>
           <td><?php echo $row['mentee']; ?> </td>
            <td><?php echo $row['username_mentee']; ?> </td>
            <td><?php echo $row['major']; ?> </td>
          </tr><?php } ?>

 

 

its show error..:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\xampp\htdocs\nrsh\all.php on line 153

 

 

how to  solve it?

plz help me

 

Link to comment
https://forums.phpfreaks.com/topic/143784-how-to-solve-this-error/
Share on other sites

this is my page.php

 

<?php
require_once('include/session.php');
require_once('include/user_auth_fns.php');

$cur_login = $_SESSION["username"];
$conn= db_connect();

$aa=0;

$query = "SELECT mm.mentee, mm.username_mentee, mp.major ".
"FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".
   "ON mp.mentee_id = mm.username_mentee".
        "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee";	

  $result = $conn->query($query);
$query1 = "select major from mentee_personal_details where mentee_id = '$m'";

?>

<!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=iso-8859-1" />

<title>Untitled Document</title>
<script LANGUAGE="JavaScript">
<!--
// Nannette Thacker http://www.shiningstar.net
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
return true ;
else
return false ;
}
// -->
</script>


<script type="text/javascript" src="calendarDateInput.js">

/***********************************************
* Jason's Date Input Calendar- By Jason Moon http://calendar.moonscript.com/dateinput.cfm
* Script featured on and available at http://www.dynamicdrive.com
* Keep this notice intact for use.
***********************************************/

</script>
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript" src="ddaccordion.js">

/***********************************************
* Accordion Content script- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

</script>

<script type="text/javascript">
<!--




ddaccordion.init({
headerclass: "submenuheader", //Shared CSS class name of headers group
contentclass: "submenu", //Shared CSS class name of contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click" or "mouseover
mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
collapseprev: true, //Collapse previous content (so only one open at any time)? true/false 
defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
animatedefault: false, //Should contents open by default be animated into view?
persiststate: true, //persist state of opened contents within browser session?
toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["suffix", "<img src='image/images/plus_n.gif' class='statusicon' />", "<img src='image/images/minus_n.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively  ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
	//do nothing
},
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
	//do nothing
}
})
//-->
</script>

<link href= "2col_leftNav1.css" rel="stylesheet" type="text/css" />
<link href= "pink_menu_left.css" rel="stylesheet" type="text/css" />

<link href="dropdowntabfiles/ddcolortabs.css" rel="stylesheet" type="text/css" />
<link href="dropdowntabfiles/dropdowntabs.js" rel="stylesheet" type="text/css" />

</head>

<body>

<div id="masthead">
  
   <div align="left"></div>
</div>

  <div id="masthead_1">
  <table width="300" border="0" align="right">
  <tr>
    <td><font class=label face="Verdana" size="2"><?php echo $_SESSION["name"]; ?> | time | Date |<a href="nlogout.php"> Logout</a>  </font></td>
  </tr>
</table>
<div id="colortab_1">
<div id="colortab" class="ddcolortabs">
<ul>
<li><a href="nprofile1.php" title="profile" ><span>PROFILE</span></a></li>
<li><a href="nforms.php" title="froms" ><span>FORMS</span></a></li>
<li><a href="view_report_menu.php" title="mentor" ><span>MENTOR</span></a></li>
<li><a href="nmanagementee.php" title="mentee" ><span>MENTEE</span></a></li>
<li><a href="mentor_setting.php" title="mysetting" ><span>MY SETTING</span></a></li>
</ul>
</div>
</div>
<div class="ddcolortabsline"> </div>                                   

  
  </div>
<div id="content"> 
  <div class="story">this features for own mentee 
    

-> all </div>
  <div id="breadCrumb_1">
    
    <table width="567" border="0" align="center">
      <tr>
        <td> </td>
        <td> </td>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
        <td width="109" bgcolor="#FFD9D9"><div align="center">No</div></td>
        <td width="111" bgcolor="#FFD9D9">Name</td>
        <td bgcolor="#FFD9D9" width="149"><div align="center">Id</div></td>
        <td bgcolor="#FFD9D9" width="182"><div align="center">Major</div></td>
      </tr>
      <tr>
  <?php
		while ($row = mysqli_fetch_assoc($result)){ 
		$aa = $aa + 1;
		?>	
        <td><?php echo $aa; ?> </td>
        <td><?php echo $row['mentee']; ?> </td>
        <td><?php echo $row['username_mentee']; ?> </td>
        <td><?php echo $row['major']; ?> </td>
      </tr><?php } ?>
    </table>
  </div>
</div>

<div id="navBar">
  <div id="search"></div>

  <div class="relatedLinks">
    <h3> <div class="glossymenu">	
  <a href="nmanagementee_assign.php"  class="menuitem">Manage Mentee</a>
 <a class="menuitem submenuheader" href="#" >Own Mentee</a>	 
	<div class="submenu">
<ul>
<li><a href="#">All</a></li>
<li><a href="name.php">Name</a></li>
<li><a href="#">Id</a></li>
<li><a href="#">Cohort</a></li>
<li><a href="#">Course</a></li>	

</ul>

</div> 
<a href="#"  class="menuitem">Status</a>


</div> </h3>
  </div>
  </div>
</body>
</html>

change...

$result = $conn->query($query1);

 

to this, in order to see the error, because $conn->query is returning FALSE...

 

$result = $conn->query($query1) or die ( mysqli_error () );

 

print f is probably right, and making that cahnge may give you the error... but can you post include/user_auth_fns.php

include/user_auth_fns.php

 

<?php
require_once('db_fns.php');

function register($name, $username, $password, $userlevel, $department, $status, $nationality)
// register new person with db
// return true or error message
{
  // connect to db
  $conn = db_connect();  
   
  // check if username is unique 
  $result = $conn->query("select * from user where username='$username'"); 
  if (!$result)
    throw new Exception('Could not execute query');
  if ($result->num_rows>0) 
    throw new Exception('That username is taken - go back and choose another one.');

  // if ok, put in db
  $result = $conn->query("insert into user (name, username, password, userlevel, department, status, nationality) values ('$name', '$username', sha1('$password'), '$userlevel', '$department', '$status', '$nationality')");
  
  if ($userlevel==4){
  
  $conn->query("insert into mentormentee (mentor, username_mentor, mentee, username_mentee) values ('','','$name', '$username')");
  
  $conn->query("insert into mentee_personal_details (mentee_id, fullname, postal_address1, postal_address2, postal_address3, postal_zip, post_telephone, degree, major, race, marital_status, hobbies,  permanent_address1, permanent_address2, permanent_address3, per_zip, per_telephone) values ('$username','$name','', '', '', '', '', '', '', '', '', '', '', '', '', '', '')");
  
  $conn->query("insert into family_details (mentee_id, family_membername, relationship, occupation) values ('$username', '', '', '')");
  

  $conn->query("insert into results ('mentee_id', 'spm_stpm_school', 'spm_stpm_year1', 'spm_stpm_certificate', 'spm_stpm_year2', 'dip_deg_school', 'dip_deg_school_year1', 'dip_deg_school_certificate', 'dip_deg_school_year2') values ('$username', '', '', '', '', '', '', '', '')");
  
  $conn->query("insert into curiculum ('mentee_id', 'co_activity, co_post, co_year') values ('$username', '', '', '')");
  
  $conn->query("insert into semester_system (mentee_id, gpa, cgpa, semester_no, code, subject, credit_hour, grade) values ('$username', '', '', '', '', '', '', '')");
  }
  
if ($userlevel==2 OR 3){
$conn->query("insert into mentor_personal_details (staff_id, fullname, postal_address1, postal_address2, postal_address3, postal_zip, post_telephone, degree, race, marital_status, permanent_address1, permanent_address2, permanent_address3, per_zip, per_telephone) values ('$username','$name','', '', '', '', '', '', '', '', '', '', '', '', '')");


} 
  if (!$result)
    throw new Exception('Could not register in database - please try again later.');

  return true;
  }
  //test function
  function test($nama, $id, $course, $intake){
  //connect database
  $conn = cdb_connect();
  
  $result3 = $conn->query("insert into user(nama, id, course, intake) values ('$nama', '$id', '$course', '$intake')");
  
  if($result3){ ?>
		<SCRIPT LANGUAGE="Javascript">

			alert('The data successfully UPDATE!');
		</SCRIPT> <?php	
	}else{ ?>
		<SCRIPT LANGUAGE="Javascript">
			alert('The data cannot be UPDATE!');
		</SCRIPT> <?php	
	}
  
  }

function add_profile($staff_id, $fullname,  $postal_address1, $postal_address2, $postal_address3, $postal_zip, $post_telephone, $degree, $race, $marital_status,
			$permanent_address1, $permanent_address2, $permanent_address3, $per_zip, $per_telephone){
	//connect database
$conn = db_connect();


if (!$result1){
    throw new Exception('Could not add in database - please try again later.');
}
  return true;
} 


function check_valid_user()
// see if somebody is logged in and notify them if not
{
  if (isset($_SESSION['username']))
    return true;
  else
    return false;
}




?>



change...

$result = $conn->query($query1);

 

to this, in order to see the error, because $conn->query is returning FALSE...

 

$result = $conn->query($query1) or die ( mysqli_error () );

 

Well, sorry for the run around, but everything is fine in the code... follow printf's recomendation and see if you get any errors.

i change

$result = $conn->query($query1); to result = $conn->query($query1) or die (mysqli_error());

 

now the error said..warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\Program Files\xampp\htdocs\nrsh\all.php on line 20

 

line 20 is result = $conn->query($query1) or die (mysqli_error());

In which case I'd say the problem was with your query;

 

Try echo'ing your query before you run it, so...

 

$query = "SELECT mm.mentee, mm.username_mentee, mp.major ".

"FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".

  "ON mp.mentee_id = mm.username_mentee".

        "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee"; 

 

  $result = $conn->query($query);

 

should be

 

$query = "SELECT mm.mentee, mm.username_mentee, mp.major ".

"FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".

  "ON mp.mentee_id = mm.username_mentee".

        "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee"; 

 

die($query);

 

  $result = $conn->query($query);

i agree wit u..coz if i do like this...

 

<?php
require_once('include/session.php');
require_once('include/user_auth_fns.php');

$cur_login = $_SESSION["username"];
$conn= db_connect();

$aa=0;

$query = "select  mentee from mentormentee where username_mentor = '$cur_login'"; 
$result = $conn->query($query);


?>

 

 

<?php
		while ($row = mysqli_fetch_assoc($result)){ 
		$aa = $aa + 1;
		?>	
        <td><div align="center"><?php echo $aa; ?> </div></td>
        <td><div align="center"><?php echo $row['mentee']; ?> </div></td>
        
      </tr><?php } ?>

 

its show the correct outpu without error

now its show error...

in window its show like this:

 

SELECT mm.mentee, mm.username_mentee, mp.major FROM mentormentee mm LEFT JOIN mentee_personal_details mp ON mp.mentee_id = mm.username_menteeWHERE mm.username_mentor = 'hod' AND mp.mentee_id = mm.username_mentee

ok, change it to this...

 

$query = "SELECT mm.mentee, mm.username_mentee, mp.major ".

"FROM mentormentee mm LEFT JOIN mentee_personal_details mp ".

  "ON mp.mentee_id = mm.username_mentee ".

        "WHERE mm.username_mentor = '$cur_login' AND mp.mentee_id = mm.username_mentee"; 

 

 

  $result = $conn->query($query);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.