Jump to content

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given


unioncraft

Recommended Posts

When i try and use this app on my website i get the error,

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/unionc/public_html/auction/scripts/updateTables.php on line 15

<?php
    $now = time();

add_column_if_not_exist("WA_SellPrice", "seller", "VARCHAR( 255 ) NULL");
add_column_if_not_exist("WA_SellPrice", "buyer", "VARCHAR( 255 ) NULL");
add_column_if_not_exist("WA_Players", "canBuy", "INT(11) NOT NULL DEFAULT  '0'");
add_column_if_not_exist("WA_Players", "canSell", "INT(11) NOT NULL DEFAULT  '0'");
add_column_if_not_exist("WA_Players", "isAdmin", "INT(11) NOT NULL DEFAULT  '0'");
add_column_if_not_exist("WA_Auctions", "created", "INT(11) NULL");


function add_column_if_not_exist($table, $column, $column_attr){
    $exists = false;
    $columns = mysql_query("show columns from $table");
    while($c = mysql_fetch_assoc($columns)){
        if($c['Field'] == $column){
            $exists = true;
            break;
        }
    }      
    if(!$exists){
        mysql_query("ALTER TABLE `$table` ADD `$column`  $column_attr");
    }
}

?>

Please Help!

Link to comment
Share on other sites

Are you sure you have a value assigned to your $table variable? Tray echoing it out to check.

 

To use mysql_error, change your query to:

$columns = mysql_query("show columns from $table") or die(mysql_error());

And if you can't work out (if you do get an error) from the error produced then post that error here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.