Jump to content

Recommended Posts

This is my code for my php website and i encountered an error

 

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\Diary2\home.php on line 74.

 

hope that this problem will be solved coz i really need to finish this before august. tahks..

 

<html>

<head><title>The Diary</title>

<script>

function logout(){

var a=confirm("Are you sure you want to log out?");

if (a==true){

alert("Visit our site again. We will miss you!");

window.location="main.php";

}

}

</script>

 

 

</head>

<?php

$user=$_GET['user'];

mysql_connect('localhost','root','') or die(mysql_error());

mysql_select_db('amaregister') or die(mysql_error());

 

?>

 

 

 

 

 

<body body background="bgbg.png">

<br>

<br>

<br>

<br>

<table align="center" width="67%" bgcolor="white"  border="2" cellspacing="0">

<tr>

<td align="center"><img src="logo.png" ></td>

</tr>

</table><br>

 

<table align="center" width="67%" bgcolor="white"  border="1" cellspacing="0">

<tr><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">

<td align="center"><a href="home.php?user=<?php echo $user; ?>"><img src="home.png" ></td>

<td align="center"><a href="write.php?user=<?php echo $user; ?>"><img src="write.png" > </td>

<td align="center"><a href="mydiary.php?user=<?php echo $user; ?>"><img src="diary.png" ></td>

<td align="center"><img src="logout.png" onClick="logout()"></td>

</tr>

</table>

<br>

 

<table  border="1"  align="center" width="67%" bgcolor="white" cellspacing="0">

<tr>

<td>

<br>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">

<p align="left"><font face="inkpen2 script" size="4" color="#FF00FF">    <?php print strftime('%c');?></font></p>

<p align="left"><font face="DimWitRight" size="8" color="#FF00FF"> Welcome to your Diary <?php echo $user; ?>!</font></p>

 

<br>

 

<?php

mysql_connect('localhost','root','') or die(mysql_error());

mysql_select_db('amaregister') or die(mysql_error());

 

 

$sql="SELECT

firstname,

lastname,

age,

email,

username,

password,

FROM amaregister.register

WHERE username = '".$user."'";

 

$resSql=mysql_query($sql);

 

if(mysql_num_rows($resSql)>0) //line 74

{

while($rows=mysql_fetch_array($resSql))

{

?>

<tr cellspacing="5">

<td width="40"><font class="textL">Name: </font></td>

<td><font class="com_textL"><?php echo $rows['firstname']; echo " "; echo $rows['lastname']; ?> </font></td>

</tr>

<tr>

<td ><font class="textL">Age: </font></td>

<td ><font class="com_textL"><?php echo $rows['age']; ?> </font></td>

</tr>

<tr>

<td ><font class="textL">E-mail Address: </font></td>

<td ><font class="com_textL"><?php echo $rows['email']; ?> </font></td>

</tr>

<tr>

<td ><font class="textL">Username: </font></td>

<td ><font class="com_textL"><?php echo $rows['username']; ?> </font></td>

</tr>

<?php } }?>

 

 

 

</td>

</tr>

</form>

</table>

<br>

<br>

<center>

<font style="font-family: perpetua; font-size: 14px; color: black; text-decoration: none;">

The Diary are trademarks or registered trademarks of AMA Biñan Section-CA S.Y. 2011-12.<br>

© 2011 AMA Biñan Section-CA. All rights reserved.

</font>

</center>

</body>

 

</html>

Link to comment
https://forums.phpfreaks.com/topic/241858-my-sql-error-pls-help-us-tt/
Share on other sites

Seems pretty obvious to me.

 

mysql_num_rows() was given a boolean value ( true, false ) when it expected something else.

 

What variable are you using to call mysql_num_rows()? What function is giving that variable a value? What could cause that function to return a boolean value rather than a resource?

<html>
<head><title>The Diary</title>
<script>
function logout(){
var a=confirm("Are you sure you want to log out?");
if (a==true){
alert("Visit our site again. We will miss you!");
window.location="main.php";
}
}
</script>


</head>
<?php
$user=$_GET['user'];
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('amaregister') or die(mysql_error());

?>





<body body background="bgbg.png">
<br>
<br>
<br>
<br>
<table align="center" width="67%" bgcolor="white"  border="2" cellspacing="0">
<tr>
<td align="center"><img src="logo.png" ></td>
</tr>
</table><br>

<table align="center" width="67%" bgcolor="white"  border="1" cellspacing="0">
<tr><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
   <td align="center"><a href="home.php?user=<?php echo $user; ?>"><img src="home.png" ></td>
   <td align="center"><a href="write.php?user=<?php echo $user; ?>"><img src="write.png" > </td>
   <td align="center"><a href="mydiary.php?user=<?php echo $user; ?>"><img src="diary.png" ></td>
   <td align="center"><img src="logout.png" onClick="logout()"></td>
</tr>
</table>
<br>

<table   border="1"  align="center" width="67%" bgcolor="white" cellspacing="0">
<tr>
<td>
<br>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
<p align="left"><font face="inkpen2 script" size="4" color="#FF00FF">    <?php print strftime('%c');?></font></p>
<p align="left"><font face="DimWitRight" size="8" color="#FF00FF"> Welcome to your Diary <?php echo $user; ?>!</font></p>

<br>

<?php
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('amaregister') or die(mysql_error());


$sql="SELECT
   firstname, 
   lastname, 
   age, 
   email,
   username,
   password,
   FROM amaregister.register 
   WHERE username = '".$user."'";
            
  if ($resSql=mysql_query($sql)) {
      
      if(mysql_num_rows($resSql)>0) //line 74
         {               
            while($rows=mysql_fetch_array($resSql))
               {
?>
   <tr cellspacing="5">
      <td width="40"><font class="textL">Name: </font></td>
      <td><font class="com_textL"><?php echo $rows['firstname']; echo " "; echo $rows['lastname']; ?> </font></td>
   </tr>      
   <tr>
      <td ><font class="textL">Age: </font></td>
      <td ><font class="com_textL"><?php echo $rows['age']; ?> </font></td>
   </tr>         
   <tr>
      <td ><font class="textL">E-mail Address: </font></td>
      <td ><font class="com_textL"><?php echo $rows['email']; ?> </font></td>
   </tr>
   <tr>
      <td ><font class="textL">Username: </font></td>
      <td ><font class="com_textL"><?php echo $rows['username']; ?> </font></td>
   </tr>
<?php } }
}
else { die(mysql_error()); } ?>



</td>
</tr>
</form>
</table>
<br>
<br>
<center>
      <font style="font-family: perpetua; font-size: 14px; color: black; text-decoration: none;">
      The Diary are trademarks or registered trademarks of AMA Biñan Section-CA S.Y. 2011-12.<br>
      © 2011 AMA Biñan Section-CA. All rights reserved.
      </font>
      </center>
</body>

</html>

 

Also, why do you connect to the database twice?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.