NicePHP77 Posted December 2, 2013 Share Posted December 2, 2013 Not sure how to correct this error, searched the forums, but couldn't find solution: $conn=mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error());mysql_select_db($dbname) or die("Unable to select database because: " . mysql_error()); mysql_query("DROP TABLE `grn_gemcart_data`"); $sql = "CREATE TABLE IF NOT EXISTS " . $dbtable . " ("; $sql .= "v_products_model varchar(24), "; $sql .= "PRIMARY KEY(v_products_model), "; $sql .= "v_products_name_1 varchar(64), "; $sql .= "v_products_description_1 TEXT, "; $sql .= "v_products_image varchar(30), "; $sql .= "v_product_upc INT, "; $sql .= "v_products_price varchar(10), "; $sql .= "v_products_quantity INT, "; $sql .= "v_products_weight varchar(10), "; $sql .= "v_categories_name_1_1 varchar(255), "; $sql .= "v_categories_name_2_1 varchar(255), "; $sql .= "v_categories_name_3_1 varchar(255), "; $sql .= "v_categories_name_4_1 varchar(255), "; $sql .= "v_categories_name_5_1 varchar(255), "; $sql .= "v_categories_name_6_1 varchar(255), "; $sql .= "v_categories_name_7_1 varchar(255), "; $sql .= "v_manufacturers_name varchar(50), "; $sql .= "v_manufacturers_image varchar(50), "; $sql .= "v_status TINYINT, "; $sql .= "v_products_tax_class_id TINYINT, "; $sql .= "EOREOR varchar(10)"; $sql .= ");"; mysql_query($sql); $limit=50000; $q = "select * from " . $src; $r = mysql_query($q); while(($ar = mysql_fetch_array($r, MYSQL_ASSOC)) && $limit > 0 ){ //start $newsql = "REPLACE into " . $dbtable ." "; $newsql .= "(v_products_model,v_products_name_1,v_products_description_1,v_products_image,v_product_upc,v_products_price,v_products_quantity,v_products_weight,v_categories_name_1_1,v_categories_name_2_1,v_categories_name_3_1,v_categories_name_4_1,v_categories_name_5_1,v_categories_name_6_1,v_categories_name_7_1,v_manufacturers_name,v_status,v_products_tax_class_id,EOREOR)"; $newsql .= " VALUES ("; Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 2, 2013 Share Posted December 2, 2013 The query before you call mysql_fetch_assoc has failed. When a query fails mysql_query() returns false. The query you have is this $q = "select * from " . $src; $r = mysql_query($q); The variable $src does not appear to be set. Quote Link to comment Share on other sites More sharing options...
NicePHP77 Posted December 2, 2013 Author Share Posted December 2, 2013 Thank you!! I am a complete noob when it comes to rewriting code. This was written for us and worked well until a php5 upgrade seems a bit stricter. Any suggestions how to fix this code so it works? thanks for any help you can give!! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 2, 2013 Share Posted December 2, 2013 Any suggestions how to fix this code so it works? Either hard code the table name into the query $q = "select * from table_name"; Or define the $src variable with the table name $src = "table_name"; $q = "select * from " . $src; Quote Link to comment Share on other sites More sharing options...
NicePHP77 Posted December 2, 2013 Author Share Posted December 2, 2013 Thanks. Hard-coded it to this: $limit=50000; $q = "select * from table_name";// $q = "select * from " . $src; $r = mysql_query($q); while(($ar = mysql_fetch_array($r, MYSQL_ASSOC)) && $limit > 0 ){ <---------------------------------------------------------- LINE 43 //start $newsql = "REPLACE into " . $dbtable ." "; $newsql .= "(v_products_model,v_products_name_1,v_products_description_1,v_products_image,v_product_upc,v_products_price,v_products_quantity,v_products_weight,v_categories_name_1_1,v_categories_name_2_1,v_categories_name_3_1,v_categories_name_4_1,v_categories_name_5_1,v_categories_name_6_1,v_categories_name_7_1,v_manufacturers_name,v_status,v_products_tax_class_id,EOREOR)"; $newsql .= " VALUES ("; //Model $newsql .= "'" . $ar['SKURcrd'] . "', "; ERROR: mysql_fetch_array() expects parameter 1 to be resource, boolean given in ... on line 43 (indicated above) Looking for any side work? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 2, 2013 Share Posted December 2, 2013 (edited) You have to change table_name to the actual name of the table you want to run the query on. I only gave table_name as a guide. I cannot tell what the table would be as I dont know what your database structure is What are you trying to do? Edited December 2, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted December 2, 2013 Share Posted December 2, 2013 you need to find out exactly what is causing the problem. start by setting php's error reporting to E_ALL (that would let you know if the variables are not defined) and checking if the query is actually failing (the code might be reusing the $r variable inside the loop.) your system apparently has php's error_reporting turned on, but it might not be set to E_ALL. add the following statements, immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(-1); next change the line - $r = mysql_query($q); to the following - $r = mysql_query($q) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
NicePHP77 Posted December 3, 2013 Author Share Posted December 3, 2013 Thanks, i did those changes and noticed a database error - strange. In looking further this files calls several other php files, it seems the guy that coded this didn't keep it up with strict standards and its hosed...need to hire it out to correct, its a pretty complicated datafeed pull, push, etc. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.