By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,601 Members | 989 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,601 IT Pros & Developers. It's quick & easy.

same code different behaviours ???? WHY ???

P: 5
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. require_once('db.php');
  4. include('functions.php');
  5. $user = get_username ( $_SESSION['user_id'] );
  6.  
  7.     //if ( $_SESSION['logged_in'] ):
  8.     checkLogin ( '1 2' );
  9.  
  10. ?>
  11. <html>
  12. <title>Manage Articles </title>
  13. <head><link href="css/styles.css" rel="stylesheet" type="text/css" /></head>
  14. <body>
  15.  
  16.  
  17.  
  18.  
  19. <?php
  20. if($_REQUEST['action']=="edit")
  21.     {
  22.         mysql_query("UPDATE articles SET status = '0' WHERE id={$_REQUEST['id']};");
  23.     }
  24. if($_REQUEST['action']=="read")
  25.     {
  26.     $s = mysql_query("SELECT * FROM articles where id={$_REQUEST['id']};");
  27.     $a = 0;
  28.     while( $article = mysql_fetch_array($s) )
  29.     {
  30.         echo "<b> Article Details </b></br></br></br>";
  31.         echo "<i>Title </i>:: &nbsp;&nbsp;".$article['title']."</br></br>";
  32.         echo "<i>Keyword</i> :: &nbsp;&nbsp;".$article['keyword']."&nbsp;</br></br>";
  33.         echo "<i>Body</i> :: &nbsp;&nbsp;".$article['body']."&nbsp;</br></br>";
  34.         echo "<i>Submitted By</i> :: &nbsp;&nbsp;".$article['user']."&nbsp;</br></br>";
  35.         echo "<i>Submitted On</i> :: &nbsp;&nbsp;".$article['date']."&nbsp;</br></br></br>";
  36.         echo "<hr>";
  37.         $a++;
  38.     }
  39.  
  40.     }
  41. if($_REQUEST['action']=="del")
  42.     {
  43.         mysql_query("DELETE FROM articles WHERE id={$_REQUEST['id']};");
  44.     }
  45. if($_REQUEST['action']=="activate")
  46.     {
  47.         mysql_query("UPDATE articles SET status = '1' WHERE id={$_REQUEST['id']};");
  48.     }
  49. $result=mysql_query("SELECT * FROM articles where status = 0 and user = \"$user\" order by id;");
  50. $i=0;
  51. echo "<table border = 1 class = border1>";
  52. echo "<tr><a><b>Inactive Articles</b></a></tr>";
  53. echo "<td>Title</td>";
  54. echo "<td>Submitted By</td>";
  55. echo "<td>Date</td>";
  56. echo "<td></td>";
  57. echo "<td></td>";
  58. echo "<td></td></tr>";
  59.     while( $row = mysql_fetch_array($result) )
  60.     {
  61.         echo "<td>".$row['title']."</td>";
  62.         //echo "<td >".$row['keyword']."&nbsp;</td>";
  63.         //echo "<td >".$row['body']."&nbsp;</td>";
  64.         echo "<td >".$row['user']."&nbsp;</td>";
  65.         echo "<td >".$row['date']."&nbsp;</td>";
  66.  
  67.         echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_articles.php?action=del&id=".$row['id']."><span class=red>Delete</span></a></td>";
  68.         echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_articles.php?action=activate&id=".$row['id']."><span class=red>Edit</span></a></td>";
  69.         echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_articles.php?action=read&id=".$row['id']."><span class=red>Read</span></a></td></tr>";
  70.         //echo "<td class=tabval></td>";
  71.         //echo "</tr>";
  72.         $i++;
  73.  
  74.     }
  75.     echo "</table>";
  76.  
  77.     ?>
  78.     <?php
  79.  
  80.  
  81. $result=mysql_query("SELECT * FROM articles where status = 1 and user = \"$user\" order by id;");
  82. $i=0;
  83. echo "</br></br></br>";
  84. echo "<hr>";
  85. echo "<table border = 1>";
  86. echo "</br>";
  87. echo "<tr><a ><b>Active Articles</b></a></tr>";
  88. echo "<td>Title</td>";
  89. echo "<td>Submitted By</td>";
  90. echo "<td>Date</td>";
  91. echo "<td></td>";
  92. echo "<td></td>";
  93. echo "</tr>";
  94.     while( $row = mysql_fetch_array($result) )
  95.     {
  96.     echo "<td>".$row['title']."</td>";
  97.         //echo "<td >".$row['keyword']."&nbsp;</td>";
  98.         //echo "<td >".$row['body']."&nbsp;</td>";
  99.         echo "<td >".$row['user']."&nbsp;</td>";
  100.         echo "<td >".$row['date']."&nbsp;</td>";
  101.  
  102.         echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_articles.php?action=del&id=".$row['id']."><span class=red>Delete</span></a></td>";
  103.         //echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_article.php?action=suspend&id=".$row['id']."><span class=red>Suspend</span></a></td>";
  104.         echo "<td><a onclick=\"return confirm('Are you sure ?');\" href=manage_articles.php?action=read&id=".$row['id']."><span class=red>Read</span></a></td></tr>";
  105.         //echo "<td class=tabval></td>";
  106.         //echo "</tr>";
  107.         $i++;
  108.  
  109.     }
  110.  
  111.     ?>
  112.     </table>
  113.     </body>
  114.     </html>
This page works correctly as i need with the mysql_fetch_array() function but with the same code as i'll show below, it gives me an error like mysql_fetch_array() is not a valid mysql result source .
Why is it ?

Expand|Select|Wrap|Line Numbers
  1. <table>
  2.                        <?php if($_REQUEST['action']=="view")
  3.     {//{$_REQUEST['id']};
  4.     $s = mysql_query("select * from cards where card={$_REQUEST['card']}");
  5.     $a = 0;
  6.     while( $article = mysql_fetch_array($s) )
  7.     {
  8.  
  9.     //$sql10=mysql_query("select * from cards where card={$_REQUEST['card']};")or die("<h5 align=center>Could Not Find the Table named cards</h5>") ;
  10.     //            while($rs10=mysql_fetch_array($sql10))
  11.     //            {
  12.                 echo"<tr><embed src='./_cards/".$article['card']."' border=0 width=500 height=400 type='application/x-shockwave-flash'></embed></tr>";
  13.                 $a++;
  14.                 }
  15. }
  16.                 ?> <?php if($_REQUEST['action']=="show")
  17.     {print"<a class='titlegreen'>Birthday Cards </a></br></br>";
  18.     print"<tr>";
  19.     $sql=mysql_query("select * from cards where type = 'Birthday' ") or die("<h5 align=center>Could Not Find the Table named cards</h5>");
  20.  
  21.                 while($rs=mysql_fetch_array($sql))
  22.  
  23. {
  24. print"<td>";
  25. print"<table>";
  26. print"<tr><a href= index.php?action=view&card=".$rs['card']."><img src='./_cards/".$rs["thumbnail"]."' width=60 height=50 border=0></a></tr>";
  27. echo "<tr class='bodyblue' align='center'><div align='center'>";
  28. echo $rs['name'];
  29. echo"</div>";
  30. print"</tr>";
  31. print"</table>";
  32. print"</td>";
  33.  
  34.  
  35. }
  36. print"</tr>";
  37. }

Plese help i keep gettin this kinda prblms
Dec 10 '07 #1
Share this Question
Share on Google+
2 Replies


ak1dnar
Expert 100+
P: 1,584
The meaning of this error is, your query string is not giving a valid result set after executing the query using mysql_query().

Before pass the query to mysql_query() function, just print it back to the web page and then manually execute the generated query string in the query analyser. Then you can find out the, errors in the sql statement (If any and I guess)
Thanks.
Dec 10 '07 #2

100+
P: 111
hi,
not sure if this is the reason as i don't know your database structure

in your first example you are using
[PHP]SELECT * FROM articles where id={$_REQUEST['id']};[/PHP]

i'm assuming that the id is an interger.

whereas in the second example you are using

[PHP]select * from cards where card={$_REQUEST['card']}[/PHP]

is the $_REQUEST['card'] meant to be a string or an interger.

if string then you need apostrophes around the $_REQUEST['card']
Dec 10 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.