473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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
2 1488
ak1dnar
1,584 Expert 1GB
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
nitinpatel1117
111 100+
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

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

Similar topics

4
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or...
8
by: Michael B Allen | last post by:
Is the string returned by getenv guaranteed to be the same string supplied to putenv plus the offset of the variable name and equals sign? Because of API constraints I do not want to save a...
2
by: Bart | last post by:
Hi, I ran the same code with two different providers (oledb abd sqlclient), and i got two different behaviours. The code with OLEDB runs perfect without error. The same code with SQLClient...
2
by: Bart | last post by:
Hi, I ran the same code with two different providers (oledb abd sqlclient), and i got two different behaviours. The code with OLEDB runs perfect without error. The same code with SQLClient...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.