SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard nofel's Avatar
    Join Date
    Aug 2007
    Location
    Earth
    Posts
    1,766
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Reteriving names based on id not working

    hi folks i m working on a query and its giving me error saying
    mysql_fetch_array(): supplied argument is not a valid
    I don't know where i m going wrong i been over it again n again
    here is my code
    Code PHP:
    <?php require("includes/functions.php"); ?>
    <?php
    if(isset($_GET['page'])){
        $sub = $_GET['page'];
        $sub_sel =  get_heading($sub);
     
    }else{
        $sub = "";
    }
    ?>
    <body>
     
    <div class="container">
      <div class="sidebar1">
      <?php 
      $con = mysql_connect("localhost","root","");
      confirm($con);
      $seldb = mysql_select_db("widget_corp");
     confirm($seldb);
     //$query = "select * from subjects";
    //$subject_set = mysql_query($query);
     $parent = get_subjects($subject);
    ?>
    <ul>
     
    <?php 
     while($subjects=mysql_fetch_array($parent))
     {
             echo "<a href=\"\"><li>{$subjects["menu_name"]}</a></li>";
     
                $pageResult = get_pages($subjects["id"]);
                echo "<ul class=\"nested\">";
                while($row = mysql_fetch_array($pageResult)){
                    echo "<a href=\"content.php?page=" . urlencode($row["id"]). "\"><li>{$row["menu_name"]}</a></li>";
                }
                echo "</ul>";
     }
      ?>
    </ul>  
        </div>
      <div class="content">
     
      <h1><?php $sub_sel["menu_name"] ?></h1>
        <?php
            echo ($sub);
            ?>
        <!-- end .content --></div>
      <!-- end .container --></div>
    and here is that function
    Code PHP:
    function get_heading($subject_id){
        $query ="SELECT * FROM"; 
        $query .= "subjects "; 
        $query .= "where id = {$subject_id}";
        $query .= "limit by 1";
        $result_set = mysql_query($query);
        if($subject = mysql_fetch_array($result_set)){
            return $subject;
        }else{
            return null;
        }
    }
    what am i doing wrong
    All those who wander aren't lost.

  2. #2
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Limit 1

  3. #3
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Yea, 'limit 1' not 'limit by 1'.

    Also, your code is dangerous security wise - please read up on Sql Injection and mysql_real_escape_string

    http://en.wikipedia.org/wiki/SQL_injection
    http://php.net/manual/en/function.my...ape-string.php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •