php warning fetching a record from database

Thread Solved

Join Date: Jul 2008
Posts: 13
Reputation: prashanth18 is an unknown quantity at this point 
Solved Threads: 0
prashanth18 prashanth18 is offline Offline
Newbie Poster

php warning fetching a record from database

 
0
  #1
Sep 10th, 2008
hi ,

PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\Domains\eazygurus.com\wwwroot\courses.php on line 45

im getting this error please help me out from this. im attaching the php file and copying my database values........

Table structure for table `course`
--

  1. CREATE TABLE `course` (
  2. `id` INT(50) NOT NULL AUTO_INCREMENT,
  3. `course` VARCHAR(50) NOT NULL,
  4. `subcourse` VARCHAR(50) NOT NULL,
  5. `fee` INT(50) NOT NULL,
  6. `content` VARCHAR(1000) NOT NULL,
  7. `DATE` TEXT NOT NULL,
  8. PRIMARY KEY (`id`)
  9. ) ENGINE=INNODB DEFAULT CHARSET=latin1 AUTO_INCREMENT=34 ;
  10.  
  11. --
  12. -- Dumping data for table `course`
  13. --
  14.  
  15. INSERT INTO `course` (`id`, `course`, `subcourse`, `fee`, `content`, `DATE`) VALUES
  16. (24, 'java', 'dddddddddddsssssssss', 212121, '11111111111111111111111', '2008-08-29');
Last edited by peter_budo; Sep 10th, 2008 at 3:43 pm. Reason: Keep It Organized - please use [code] tags
Attached Files
File Type: php courses.php (3.7 KB, 5 views)
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 846
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 138
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Practically a Posting Shark

Re: php warning fetching a record from database

 
0
  #2
Sep 10th, 2008
where is your mysql_connect ?
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 19
Reputation: NormandP is an unknown quantity at this point 
Solved Threads: 3
NormandP NormandP is offline Offline
Newbie Poster

Re: php warning fetching a record from database

 
0
  #3
Sep 10th, 2008
When you go to "courses.php" for the FIRST TIME, do you have a query after the .php ?

Something like:
.../courses.php?course=course_name&subcourse=something

// courses & subcourse values are mandatory as programmed with:
$course=$_GET['course']
$subcourse= $_GET['subcourse'];
Last edited by NormandP; Sep 10th, 2008 at 9:52 am. Reason: ameliorate
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: php warning fetching a record from database

 
0
  #4
Sep 10th, 2008
this line should be like this:
  1. $query=("select * from course where course='".$course."'") or die(mysql_error());
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: saikishore is an unknown quantity at this point 
Solved Threads: 7
saikishore saikishore is offline Offline
Light Poster

php warning fetching a record from database

 
0
  #5
Sep 11th, 2008
Hi Shanthi..
here the total code working properly...
the problem arises when i write where condition......
here

  1. $course=$_GET['course'];
  2.  
  3. $query=("select * from course where course='".$course."' ) or die(mysql_error());
  4. while($result=mysql_fetch_array($query))
  5. {
  6.  
  7. }
  8.  


This is the part of the code where i m getting an error.
Error:mysql_fetch_array(); supplied arguement is not a valid mysql resource.
With Regards,
Kishore
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: php warning fetching a record from database

 
0
  #6
Sep 11th, 2008
hello kishor..
echo this line and tel me wat u got:
echo $course=$_GET['course'];
and also echo this statement:
  1. echo $r="select * from course where course='".$course."'";
Last edited by Shanti Chepuru; Sep 11th, 2008 at 7:26 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 197
Reputation: vssp has a little shameless behaviour in the past 
Solved Threads: 5
vssp vssp is offline Offline
Junior Poster

Re: php warning fetching a record from database

 
0
  #7
Sep 11th, 2008
try this
  1. echo $r="select * from course where course=$course;
  2.  
Thanks
VSSP
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: saikishore is an unknown quantity at this point 
Solved Threads: 7
saikishore saikishore is offline Offline
Light Poster

Re: php warning fetching a record from database

 
0
  #8
Sep 11th, 2008
hi shanthi,
when i echo$r= "select * from course where course='".$course."'";
i am getting the output as
select * from course where course="

more over in the echo $course=$_get['course'];
doesn't print anything
With Regards,
Kishore
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,073
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: php warning fetching a record from database

 
0
  #9
Sep 11th, 2008
so, you didn't get any data in $_GET['course'];
tel me ,from where you are getting this variable..
or post needed code...
Last edited by Shanti Chepuru; Sep 11th, 2008 at 7:41 am.
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: saikishore is an unknown quantity at this point 
Solved Threads: 7
saikishore saikishore is offline Offline
Light Poster

Re: php warning fetching a record from database

 
0
  #10
Sep 11th, 2008
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title></title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="description" content="Small Corporation" />
  7. <meta name="keywords" content="small, corporation" />
  8. <link rel="stylesheet" href="style.css" type="text/css" />
  9. <style type="text/css">
  10. <!--
  11. .style4 {color: #FFFFFF}
  12.  
  13. .style5 {color: #2D5181}
  14. -->
  15. </style>
  16. </head>
  17. <body>
  18.  
  19. <div id="contentcourse">
  20. <div id="header"></div>
  21. <ul id="menu">
  22. <li><a class="current" href="index.php">Home</a></li>
  23. <li><a href="aboutus.php">About Us</a></li>
  24. <li><a href="courses.php">Courses</a></li>
  25. <li><a href="demo_registration.php">Demo Class Registration</a></li>
  26. <li><a href="faq.php">FAQ's</a></li>
  27. <li><a href="order.php">How To Order</a></li>
  28. <li><a href="payment.php">Payment Options</a></li>
  29. <li><a href="enquiry.php">Enquiry</a></li>
  30. <li><a href="contact.php">Contact Us</a></li>
  31.  
  32. </ul>
  33.  
  34. <div id="course">
  35. <div id="title">
  36. <h3>Sub Courses</h3>
  37. </div>
  38. <br/>
  39.  
  40. <?php
  41. include("config.php");
  42. $course=$_GET['course'];
  43. $query=("select course,subcourse from course WHERE course=$course") or die(mysql_error());
  44. $ress1=mysql_query($query);
  45. while($rows=mysql_fetch_array($ress1))
  46. {
  47. $subcourse= $rows['subcourse'];
  48. ?>
  49. <font color="#666666"> <a href="courses.php?course=<?php echo $course ;?>&subcourse=<?php echo $subcourse ;?>" >
  50. <?php
  51. echo $subcourse;
  52. echo "<br>";
  53. ?>
  54. </a></font>
  55. <?php
  56. }?>
  57.  
  58. <?php $course=$_GET['course'];
  59. $subcourse= $_GET['subcourse'];
  60.  
  61. $ress2=mysql_query("select * from course where subcourse='$subcourse'") or die(mysql_error());
  62.  
  63. while($rows=mysql_fetch_array($ress2))
  64. {
  65. $subcourse= $rows['subcourse'];
  66. $fee= $rows['fee'];
  67. $content= $rows['content'];
  68.  
  69.  
  70. ?><br />
  71.  
  72. <table width="85%" border="1" bordercolor="#CCCCCC">
  73. <tr >
  74. <td width="14%" height="40" ><strong>Course:</strong></td>
  75. <td width="86%" ><?php echo $subcourse; ?></td>
  76. </tr>
  77. <tr>
  78. <td height="39"><strong>Fee:</strong></td>
  79. <td><?php echo $fee; ?></td>
  80. </tr>
  81. <tr>
  82. <td height="210"><strong>Discription:</strong></td>
  83. <td><textarea rows="13" cols="50"><?php echo $content; ?></textarea>
  84. </td>
  85. </tr>
  86. </table>
  87. <?php } ?>
  88. <p>&nbsp; </p>
  89. </div>
  90. <div id="title1">
  91. <h3 class="style5">Courses Offered</h3>
  92. </div>
  93. <div id="sidemenu">
  94.  
  95. <p>
  96. <?php
  97. $ress=mysql_query("select DISTINCT course from course ") or die(mysql_error());
  98.  
  99.  
  100. while ($row = mysql_fetch_array($ress))
  101. {
  102. $course= $row['course'];
  103. ?>
  104. <a href="courses.php?course='<?php echo $course ;?>'" >
  105.  
  106. <?php echo $row['course'];
  107. echo "<br>";
  108. }?> </a> </p>
  109.  
  110.  
  111. </div>
  112. <div id="footer"><br/>
  113. <div align="center"><span class="links"><a href="index.php">Home</a>
  114. <a href="aboutus.php">About Us</a>
  115. <a href="courses.php">Courses</a>
  116. <a href="demo_registration.php">Demo Class Registration</a>
  117. <a href="faq.php">FAQ's</a>
  118. <a href="order.php">How To Order</a>
  119. <a href="payment.php">Payment Options</a>
  120. <a href="enquiry.php">Enquiry</a>
  121. <a href="contact.php">Contact Us</a></span></div>
  122. </div>
  123. </div>
  124. </body>
  125. </html>



this is the original code what we did with out making anychanges u asked us to make.
Database has been posted in the first post of the thread..
With Regards,
Kishore
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC