Results 1 to 4 of 4

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

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

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

    dunno why, but it says that I cannot connect to the database. any ideas why?

    PHP Code:
    <?php
    include 'include/db.php';
    $query "SELECT * FROM news2";
    $result mysql_query($query) or die ("Couldn't execute query.");
    $a=1;
    while (
    $value mysql_fetch_array($result)){
    $news[1]=$value['ID'];
    $news[2]=$value['energy'];
    $news[3]=$value['date'];

    $db="INSERT INTO news (ID,energy,date) VALUES ('$news[1]','$news[2]','$news[3]'";
    $result mysql_query($db) or die ("Couldnnt execute query.");
    echo 
    "$db<br>";
    }
    ?>
    EDIT: For those curious I created this program to pull the contents of one table and insert it onto the end of another table. I have too many tables in my database right now and I am trying to prune them down a bit. See the post# 4 for the fixed version of this script.
    Last edited by james438; 11-15-2008 at 01:36 AM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    silly me. I forgot the closing parentheses. It should read:
    PHP Code:
    <?php 
    include 'include/db.php'
    $query "SELECT * FROM news2"
    $result mysql_query($query) or die ("Couldn't execute query."); 
    $a=1
    while (
    $value mysql_fetch_array($result)){ 
    $news[1]=$value['ID']; 
    $news[2]=$value['energy']; 
    $news[3]=$value['date']; 

    $db="INSERT INTO news (ID,energy,date) VALUES ('$news[1]','$news[2]','$news[3]')"
    $result mysql_query($db) or die ("Couldnnt execute query."); 
    echo 
    "$db<br>"

    ?>
    To choose the lesser of two evils is still to choose evil. My personal site

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    New problem. I am getting the error Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/a/n/i/animeviews/html/test.php on line 5.

    The database updates, but only for one row.

    PHP Code:
    <?php
    include 'include/db.php';
    $query "SELECT * FROM news2";
    $result mysql_query($query,$conn) or die ("Couldn't execute query.");
    while (
    $value mysql_fetch_array($result,MYSQL_ASSOC)){
    $marriage=$value['energy'];
    $date=$value['date'];
    $db="INSERT INTO news (marriage,date) VALUES ('$marriage','$date')";
    $result mysql_query($db) or die (mysql_last_error());
    }

    ?>
    Last edited by james438; 11-21-2008 at 09:15 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    There were two errors. In order to add content to the database I needed to add slashes. The second error involved resetting of the variable $result on line 9. I simply renamed the first $result variable to $result1. Problem solved.

    PHP Code:
    <?php
    include 'include/db.php';
    $query "SELECT * FROM news2";
    $result1 mysql_query($query) or die ("Couldn't execute query.");
    while (
    $row mysql_fetch_array($result1,MYSQL_ASSOC)){
    $marriage=$row["energy"];$marriage=addslashes($marriage);
    $date=$row["date"];
    $db="INSERT INTO news (marriage,date) VALUES ('$marriage','$date')";
    $result mysql_query($db) or die (mysql_error());
    }
    echo 
    "all done";
    ?>
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •