Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

    Hi, i'm very new to this whole business and i need a little help...
    i was following a tutorial at http://www.oxyscripts.com/item-408.html and i have run into a problem.
    Code:
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/edit_process.php on line 12
    Here is the code
    Code:
    <?php
    
    /* edit_process.php */
    include "config.php"; 
    
    $db = mysql_connect($db_host,$db_user,$db_pass); 
    mysql_select_db ($db_name) or die ("Cannot connect to database"); 
    /* We have now connected, unless you got an error message */ 
    /* We now select one news post, and bring it into some text boxes */ 
    $query = "SELECT title, news FROM news WHERE id = $_GET[id]"; 
    $result = mysql_query($query); 
    while($r=mysql_fetch_array($result))
    {   
    /* This bit sets our data from each row as variables, to make it easier to display */ 
    $title=$r["title"]; 
    $news=$r["news"]; 
    /* Now lets display the titles */ 
        echo "<form name='edit_process.php' method='post' action='edit_save.php?id=$_GET[id]'> 
      <p>Title : 
        <input type='text' name='title' value='$title'> 
      </p> 
      <p>News :</p> 
      <p> 
        <textarea name='news' cols='40' rows='6'>$news</textarea> 
      </p> 
      <p> 
        <input type='submit' name='Submit' value='Save'> 
      </p> 
    </form>"; 
    } 
    mysql_close($db); 
    
    ?>
    The problem appears to be on line twelve so i added in
    Code:
    or die ('Error: '.mysql_error ());
    after it to see if i could pinpoint the problem. I was writing this all by hand to try and cram it into my brain so i tried copy/pasting to see if i made an error... same problem.
    After adding in the above code it gave me a new error
    Code:
    Parse error: syntax error, unexpected ';' in /var/www/edit_process.php on line 12
    I am thoroughly confused, any help would be greatly appreciated

  • #2
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    Try:

    PHP Code:
    <?php

    /* edit_process.php */
    include "config.php"

    $db mysql_connect($db_host,$db_user,$db_pass); 
    mysql_select_db ($db_name) or die ("Cannot connect to database"); 
    /* We have now connected, unless you got an error message */ 
    /* We now select one news post, and bring it into some text boxes */ 
    $query "SELECT title, news FROM news WHERE id = {$_GET['id']}"
    $result mysql_query($query); 
    while(
    $r=mysql_fetch_array($result))
    {   
    /* This bit sets our data from each row as variables, to make it easier to display */ 
    $title=$r["title"]; 
    $news=$r["news"]; 
    /* Now lets display the titles */ 
        
    echo "<form name='edit_process.php' method='post' action='edit_save.php?id={$_GET['id']}'> 
      <p>Title : 
        <input type='text' name='title' value='$title'> 
      </p> 
      <p>News :</p> 
      <p> 
        <textarea name='news' cols='40' rows='6'>$news</textarea> 
      </p> 
      <p> 
        <input type='submit' name='Submit' value='Save'> 
      </p> 
    </form>"


    mysql_close($db); 

    ?>
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Same error

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    The problem lies in the MySql resource.

    PHP Code:
    $query "SELECT `title`, `news` FROM `news` WHERE `id` = {$_GET['id']}"
    Remember to use backsticks, because mysql has keywords that will confuse it with you syntax.
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]

  • #5
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the replies. I swapped that code for mine but i am still getting the same error

  • #6
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Try this:

    PHP Code:
    $query "SELECT `title`, `news` FROM `news` WHERE `id` = '".$_GET['id']."'"
    $result mysql_query($query) or die(mysql_error());
    while(
    $r mysql_fetch_array($result)) 
    You should remember to escape your $_GET['id'] too btw. Look up mysql_real_escape_string();
    Last edited by [vengeance]; 09-03-2009 at 11:54 AM. Reason: .

  • #7
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by [vengeance] View Post
    Try this:

    PHP Code:
    $query "SELECT `title`, `news` FROM `news` WHERE `id` = '".$_GET['id']."'"
    $result mysql_query($query) or die(mysql_error());
    while(
    $r mysql_fetch_array($result)) 
    You should remember to escape your $_GET['id'] too btw. Look up mysql_real_escape_string();
    Great! It worked! Thanks so much!
    I'll look into that.
    Also, mind explainig what exactly was wrong and how it was fixed?

  • #8
    Regular Coder
    Join Date
    Aug 2009
    Posts
    131
    Thanks
    28
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by accog View Post
    Great! It worked! Thanks so much!
    I'll look into that.
    Also, mind explainig what exactly was wrong and how it was fixed?
    Well actually, I'm not much of a fancy coder. I just try out stuff until my errors go away. But like the code I provided you, I always mark the database columns with ` and the values of the input with '.

    And that has always worked for me, so I don't know what else to tell you. :P

    And I'm glad it worked for you!

  • #9
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for all the feedback!

  • #10
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    It concatenated the variable outside of the string. This was really a problem of poor syntax, always make sure to use backsticks, concatenate variables, and so on. When referencing arrays like the $_GET array, use single quotes to reference the index, like $_GET['lalala']
    PHP Code:
    $aString is_string((string)array()) ? true false// true :D 
    [/CENTER]


  •  

    Posting Permissions

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