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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rathour
    New Member
    • Sep 2007
    • 5

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

    [CODE=php]<?php
    session_start() ;
    require_once('d b.php');
    include('functi ons.php');
    $user = get_username ( $_SESSION['user_id'] );

    //if ( $_SESSION['logged_in'] ):
    checkLogin ( '1 2' );

    ?>
    <html>
    <title>Manage Articles </title>
    <head><link href="css/styles.css" rel="stylesheet " type="text/css" /></head>
    <body>




    <?php
    if($_REQUEST['action']=="edit")
    {
    mysql_query("UP DATE articles SET status = '0' WHERE id={$_REQUEST['id']};");
    }
    if($_REQUEST['action']=="read")
    {
    $s = mysql_query("SE LECT * FROM articles where id={$_REQUEST['id']};");
    $a = 0;
    while( $article = mysql_fetch_arr ay($s) )
    {
    echo "<b> Article Details </b></br></br></br>";
    echo "<i>Title </i>:: &nbsp;&nbsp;".$ article['title']."</br></br>";
    echo "<i>Keyword </i> :: &nbsp;&nbsp;".$ article['keyword']."&nbsp;</br></br>";
    echo "<i>Body</i> :: &nbsp;&nbsp;".$ article['body']."&nbsp;</br></br>";
    echo "<i>Submitt ed By</i> :: &nbsp;&nbsp;".$ article['user']."&nbsp;</br></br>";
    echo "<i>Submitt ed On</i> :: &nbsp;&nbsp;".$ article['date']."&nbsp;</br></br></br>";
    echo "<hr>";
    $a++;
    }

    }
    if($_REQUEST['action']=="del")
    {
    mysql_query("DE LETE FROM articles WHERE id={$_REQUEST['id']};");
    }
    if($_REQUEST['action']=="activate")
    {
    mysql_query("UP DATE articles SET status = '1' WHERE id={$_REQUEST['id']};");
    }
    $result=mysql_q uery("SELECT * FROM articles where status = 0 and user = \"$user\" order by id;");
    $i=0;
    echo "<table border = 1 class = border1>";
    echo "<tr><a><b>Inac tive Articles</b></a></tr>";
    echo "<td>Title</td>";
    echo "<td>Submit ted By</td>";
    echo "<td>Date</td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "<td></td></tr>";
    while( $row = mysql_fetch_arr ay($result) )
    {
    echo "<td>".$row['title']."</td>";
    //echo "<td >".$row['keyword']."&nbsp;</td>";
    //echo "<td >".$row['body']."&nbsp;</td>";
    echo "<td >".$row['user']."&nbsp;</td>";
    echo "<td >".$row['date']."&nbsp;</td>";

    echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icles.php?actio n=del&id=".$row['id']."><span class=red>Delet e</span></a></td>";
    echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icles.php?actio n=activate&id=" .$row['id']."><span class=red>Edit</span></a></td>";
    echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icles.php?actio n=read&id=".$ro w['id']."><span class=red>Read</span></a></td></tr>";
    //echo "<td class=tabval></td>";
    //echo "</tr>";
    $i++;

    }
    echo "</table>";

    ?>
    <?php


    $result=mysql_q uery("SELECT * FROM articles where status = 1 and user = \"$user\" order by id;");
    $i=0;
    echo "</br></br></br>";
    echo "<hr>";
    echo "<table border = 1>";
    echo "</br>";
    echo "<tr><a ><b>Active Articles</b></a></tr>";
    echo "<td>Title</td>";
    echo "<td>Submit ted By</td>";
    echo "<td>Date</td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "</tr>";
    while( $row = mysql_fetch_arr ay($result) )
    {
    echo "<td>".$row['title']."</td>";
    //echo "<td >".$row['keyword']."&nbsp;</td>";
    //echo "<td >".$row['body']."&nbsp;</td>";
    echo "<td >".$row['user']."&nbsp;</td>";
    echo "<td >".$row['date']."&nbsp;</td>";

    echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icles.php?actio n=del&id=".$row['id']."><span class=red>Delet e</span></a></td>";
    //echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icle.php?action =suspend&id=".$ row['id']."><span class=red>Suspe nd</span></a></td>";
    echo "<td><a onclick=\"retur n confirm('Are you sure ?');\" href=manage_art icles.php?actio n=read&id=".$ro w['id']."><span class=red>Read</span></a></td></tr>";
    //echo "<td class=tabval></td>";
    //echo "</tr>";
    $i++;

    }

    ?>
    </table>
    </body>
    </html>[/CODE]

    This page works correctly as i need with the mysql_fetch_arr ay() function but with the same code as i'll show below, it gives me an error like mysql_fetch_arr ay() is not a valid mysql result source .
    Why is it ?

    [CODE=php]<table>
    <?php if($_REQUEST['action']=="view")
    {//{$_REQUEST['id']};
    $s = mysql_query("se lect * from cards where card={$_REQUEST['card']}");
    $a = 0;
    while( $article = mysql_fetch_arr ay($s) )
    {

    //$sql10=mysql_qu ery("select * from cards where card={$_REQUEST['card']};")or die("<h5 align=center>Co uld Not Find the Table named cards</h5>") ;
    // while($rs10=mys ql_fetch_array( $sql10))
    // {
    echo"<tr><embed src='./_cards/".$article['card']."' border=0 width=500 height=400 type='applicati on/x-shockwave-flash'></embed></tr>";
    $a++;
    }
    }
    ?> <?php if($_REQUEST['action']=="show")
    {print"<a class='titlegre en'>Birthday Cards </a></br></br>";
    print"<tr>";
    $sql=mysql_quer y("select * from cards where type = 'Birthday' ") or die("<h5 align=center>Co uld Not Find the Table named cards</h5>");

    while($rs=mysql _fetch_array($s ql))

    {
    print"<td>";
    print"<table>";
    print"<tr><a href= index.php?actio n=view&card=".$ rs['card']."><img src='./_cards/".$rs["thumbnail"]."' width=60 height=50 border=0></a></tr>";
    echo "<tr class='bodyblue ' align='center'> <div align='center'> ";
    echo $rs['name'];
    echo"</div>";
    print"</tr>";
    print"</table>";
    print"</td>";


    }
    print"</tr>";
    }[/CODE]


    Plese help i keep gettin this kinda prblms
    Last edited by ak1dnar; Dec 10 '07, 09:54 AM. Reason: Fixed [CODE=php] Tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    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.

    Comment

    • nitinpatel1117
      New Member
      • Jun 2007
      • 111

      #3
      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']

      Comment

      Working...