jokerboy Posted August 6, 2009 Share Posted August 6, 2009 I recently bought and installed a classifieds script from onlinescripts.net. They are not returning email so I thought I would check here. The site loads fine but when I go to post a classified I get the following error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/million/public_html/FamilyMarket/insert_product.php on line 267 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/million/public_html/FamilyMarket/insert_product.php on line 274 Warning: Cannot modify header information - headers already sent by (output started at /home/million/public_html/FamilyMarket/insert_product.php:267) in /home/million/public_html/FamilyMarket/insert_product.php on line 308 HERE IS THE CODE: Line 267: $rs0=mysql_fetch_array(mysql_query("select * from freetplclassified_products where id=" . $id)); Line 274: $rs1=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id=" . $rs0["uid"])); Line 308: header("Location: gen_confirm_mem.php?$freetplreturn_arg&errmsg=".urlencode($msg)); Thanks, JB Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/ Share on other sites More sharing options...
Maq Posted August 6, 2009 Share Posted August 6, 2009 Although, I think you have valid syntax try changing these lines respectively. 1) $rs0=mysql_fetch_array(mysql_query("select * from freetplclassified_products where id=$id)); 2) $rs1=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id={$rs0['uid']})); 3) You cannot have have a header redirect after output to the browser, including whitespace. Read more here - HEADER ERROR. If solutions for 1 and/or 2 don't work then temporarily add a "or die(mysql_error())" clause to the end of your mysql_query call. Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892274 Share on other sites More sharing options...
jokerboy Posted August 6, 2009 Author Share Posted August 6, 2009 I changed the sctipt as you suggested and go this error: Parse error: syntax error, unexpected '=' in /home/million/public_html/FamilyMarket/insert_product.php on line 268 I then tried to take out an = sign and got another error, I tried to fix that and got another error so I am lost. I put it all back here is line 268 before my attempts to fix it: $product_url=$site_root[0]."/product_desc.php?id=".$rs0["id"]; Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892299 Share on other sites More sharing options...
Maq Posted August 6, 2009 Share Posted August 6, 2009 You should really separate your query line into a block. This increases readability, easier to debug, it's cleaner, and many other reasons. As far as line 268 try this: - Curly braces escape and separate the arrays. - As long as your primary string is in double quotes your variables will interpolate, assuming correct syntax. - Associative arrays should use single quotes. $product_url="{$site_root[0]}/product_desc.php?id={$rs0['id']}"; (Note: Please use tags around code.) Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892318 Share on other sites More sharing options...
jokerboy Posted August 6, 2009 Author Share Posted August 6, 2009 I really appreciate your help with this, I am lost. I made the change and got a new error. Parse error: syntax error, unexpected '{' in /home/million/public_html/FamilyMarket/insert_product.php on line 268 Here is the block of code I hope I am woing this right. if(mysql_affected_rows()>0){ $id=mysql_insert_id(); } $freetplrow_con=mysql_fetch_array(mysql_query("select * from freetplclassified_config"));$null_char[0]=$freetplrow_con['null_char'];$site_root[0]=$freetplrow_con['site_root'];$freetplreturn_arg=($freetplreturn)?"&id=$id":''; $rs0=mysql_fetch_array(mysql_query("select * from freetplclassified_products where id=$id));$product_url="{$site_root[0]}/product_desc.php?id={$rs0['id']}";$product_url="<a href='$product_url' target='_blank' title='Click to view product'>$product_url</a>";$login_url=$site_root[0]."/signinform.php";$login_url="<a href='$login_url' target='_blank' title='Click to login now'>$login_url</a>";$rs1=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id={$rs0['uid']})); Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892323 Share on other sites More sharing options...
Maq Posted August 6, 2009 Share Posted August 6, 2009 You were missing a terminating double quote for the query on line 267 (starts with 'rs0'). But here is your code reformatted and modified (read the comments): if(mysql_affected_rows() > 0) { $id=mysql_insert_id(); } // This - $freetplrow_con=mysql_fetch_array(mysql_query("select * from freetplclassified_config")); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_config"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $freetplrow_con = mysql_fetch_array($result); $null_char[0]=$freetplrow_con['null_char']; $site_root[0]=$freetplrow_con['site_root']; $freetplreturn_arg=($freetplreturn)?"&id=$id":''; // This - $rs0=mysql_fetch_array(mysql_query("select * from freetplclassified_products where id=$id")); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_products WHERE id=$id"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $rs0 = mysql_fetch_array($result); $product_url="{$site_root[0]}/product_desc.php?id={$rs0['id']}"; $product_url="$product_url"; $login_url="{$site_root[0]}/signinform.php"; $login_url="$login_url"; // This - $rs1=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id={$rs0['uid']})); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_members WHERE id={$rs0['uid']"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $rs1 = mysql_fetch_array($result); Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892331 Share on other sites More sharing options...
jokerboy Posted August 6, 2009 Author Share Posted August 6, 2009 O.K. so I put in the new code and uploaded. I got: Parse error: syntax error, unexpected '"', expecting '}' in /home/million/public_html/FamilyMarket/insert_product.php on line 285 So really not knowing what I am doing I tried adding } after the ] on line 285 which is the line that says $sql = "SELECT * FROM freetplclassified_members WHERE id={$rs0['uid']"; THEN I got: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 I am totally frustrated. any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892437 Share on other sites More sharing options...
Maq Posted August 6, 2009 Share Posted August 6, 2009 Sorry, I forgot the closing curly brace. id={$rs0['uid']}"; Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892443 Share on other sites More sharing options...
jokerboy Posted August 6, 2009 Author Share Posted August 6, 2009 That is what I did. I guess I did not explain that very good in my last post. I'm glad I was able to see that, not bad for a noob. Anyway after I do that I get this: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 I can't figure that one out. Here is the entire page: <?php include_once "logincheck.php"; include_once "myconnect.php"; ///////---------managing extra shipping $freetplextra_shipping=-1; if( isset($_REQUEST["freetplenable_ship"]) ) { if( isset($_REQUEST["freetplextra_shipping"]) ) { $freetplextra_shipping=(real)$_REQUEST["freetplextra_shipping"]; } } ///////---------end managing extra shipping $rate=mysql_fetch_array(mysql_query("select * from freetplclassified_config")); $bold_rate=(-1)*$rate["bold_rate"]; $featured_rate=(-1)*$rate["featured_rate"]; $fp_featured_rate=(-1)*$rate["fp_featured_rate"]; $gallery_featured_rate=(-1)*$rate["gallery_featured_rate"]; $highlight_rate=(-1)*$rate["highlight_rate"]; //$item_fees=(-1)*$rate["item_fees"]; $buy_now=(-1)*$rate["buy_now"]; $additional_info=""; $freetplreturn=false; $approved="new"; $freetplmailid=21; if($rate["freetpl_prod_approval"]=="auto") { $freetplreturn=true; $approved="yes"; $freetplmailid=5; } $freetplcat_array=explode("_",$_REQUEST["cat1"]); //don't mind this $cid=$freetplcat_array[0]; //echo "cat1=".$_REQUEST["cat1"].", cid=$cid, cost=".$freetplcat_array[1]; $freetplq_cat="select * from freetplclassified_categories where id=$cid"; $freetplrow_cat=mysql_fetch_array(mysql_query($freetplq_cat)); if($rate["freetpl_same_fee"]=='yes') $item_cost=$rate["item_fees"]; else $item_cost=$freetplrow_cat["freetpl_fee"]; ////////////////////////////////////////// $freetplq_t_f="select * from freetplclassified_types_fields where freetpl_type_id=$cid"; $freetplrs_t_f=mysql_query($freetplq_t_f); $freetpl_field_ids='-1'; while($freetplrow_t_f=mysql_fetch_array($freetplrs_t_f)) $freetpl_field_ids.=','.$freetplrow_t_f["freetpl_field_id"]; //$field_q=mysql_query("select * from freetplclassified_additional_fields"); $field_q=mysql_query("select * from freetplclassified_additional_fields where freetpl_id in ($freetpl_field_ids) or freetpl_common='yes'"); while($field=mysql_fetch_array($field_q)) { if(isset($_REQUEST[$field["freetpl_name"]])&&($_REQUEST[$field["freetpl_name"]]<>"")) { $additional_info=($additional_info=="")?$field["freetpl_name"]."|".$_REQUEST[$field["freetpl_name"]]:$additional_info.";".$field["freetpl_name"]."|".$_REQUEST[$field["freetpl_name"]]; } } //echo $additional_info; ////////////////////////////////////////// if (!get_magic_quotes_gpc()) { $product_name=str_replace('$', '\$',addslashes($_REQUEST["product_name"])); $location=str_replace('$', '\$',addslashes($_REQUEST["location"])); $product_desc=str_replace('$', '\$',addslashes($_REQUEST["rte1"])); $country=str_replace('$', '\$',addslashes($_REQUEST["country"])); $state=str_replace('$', '\$',addslashes($_REQUEST["state"])); $other_state=str_replace('$', '\$',addslashes($_REQUEST["other_state"])); $additional_info=str_replace('$', '\$',addslashes($additional_info)); } else { $product_name=str_replace('$', '\$',$_REQUEST["product_name"]); $location=str_replace('$', '\$',$_REQUEST["location"]); $product_desc=str_replace('$', '\$',$_REQUEST["rte1"]); $country=str_replace('$', '\$',$_REQUEST["country"]); $state=str_replace('$', '\$',$_REQUEST["state"]); $other_state=str_replace('$', '\$',$_REQUEST["other_state"]); $additional_info=str_replace('$', '\$',$additional_info); } if($state=="") { $state=$other_state;} //$cid=(int)$_REQUEST["cat1"]; $aucid=4; $auction_period=(int)$_REQUEST["auction_period"]; $buy_price=0.0; $paypal_id=""; if (isset($_REQUEST["buy_price"])&& ($_REQUEST["buy_price"]<>"")) { if (!get_magic_quotes_gpc()) { $buy_price=str_replace('$', '\$',addslashes($_REQUEST["buy_price"])); } else { $buy_price=str_replace('$', '\$',$_REQUEST["buy_price"]); } $buy_price=(real)$buy_price; } if (isset($_REQUEST["paypal_id"])&& ($_REQUEST["paypal_id"]<>"")) { if (!get_magic_quotes_gpc()) { $paypal_id=str_replace('$', '\$',addslashes($_REQUEST["paypal_id"])); } else { $paypal_id=str_replace('$', '\$',$_REQUEST["paypal_id"]); } } $bold="no"; $featured="no"; $fp_featured="no"; $gallery_featured="no"; $highlight="no"; $expenditure=0; if($item_cost>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",-$item_cost,'Posted classified ''$product_name''','".date("YmdHis",time())."')"); } $balance=mysql_fetch_array(mysql_query("select sum(amount) as total from freetplclassified_transactions where uid=".$_SESSION["freetpl_clsplus_userid"]." group by uid")); $total=$balance["total"]; if(isset($_REQUEST["radio"]) && $_REQUEST["radio"]<>"") { $counter_id=$_REQUEST["radio"]; } else { $counter_id=0; } if (isset($_REQUEST["bold"])&&$_REQUEST["bold"]<>"") { $expenditure+=$rate["bold_rate"]; } if (isset($_REQUEST["featured"])&&$_REQUEST["featured"]<>"") { $expenditure+=$rate["featured_rate"]; } if (isset($_REQUEST["fp_featured"])&&$_REQUEST["fp_featured"]<>"") { $expenditure+=$rate["fp_featured_rate"]; } if (isset($_REQUEST["gallery_featured"])&&$_REQUEST["gallery_featured"]<>"") { $expenditure+=$rate["gallery_featured_rate"]; } if(($buy_price>0)&&($paypal_id<>"")) { $expenditure+=$rate["buy_now"]; } if (isset($_REQUEST["highlight"])&&$_REQUEST["highlight"]<>"") { $expenditure+=$rate["highlight_rate"]; } if(($expenditure<=$total) || ($expenditure<=0)) { if (isset($_REQUEST["bold"])&&$_REQUEST["bold"]<>"") { if($rate["bold_rate"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$bold_rate,'Made classifed ''$product_name'' to appear as Bold','".date("YmdHis",time())."')"); } $bold="yes"; } if (isset($_REQUEST["featured"])&&$_REQUEST["featured"]<>"") { $featured="yes"; if($rate["featured_rate"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$featured_rate,'Made classified ''$product_name'' to appear as Featured','".date("YmdHis",time())."')"); } } if (isset($_REQUEST["fp_featured"])&&$_REQUEST["fp_featured"]<>"") { $fp_featured="yes"; if($rate["fp_featured_rate"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$fp_featured_rate,'Made classified ''$product_name'' to appear as Featured on Front Page','".date("YmdHis",time())."')"); } } if (isset($_REQUEST["gallery_featured"])&&$_REQUEST["gallery_featured"]<>"") { $gallery_featured="yes"; if($rate["gallery_featured_rate"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$gallery_featured_rate,'Made classified ''$product_name'' to appear as Featured in Gallery ','".date("YmdHis",time())."')"); } } if (isset($_REQUEST["highlight"])&&$_REQUEST["highlight"]<>"") { $highlight="yes"; if($rate["highlight_rate"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$highlight_rate,'Made classified ''$product_name'' to appear as Highlighted','".date("YmdHis",time())."')"); } } if(($buy_price>0)&&($paypal_id<>"")) { if($rate["buy_now"]>0) { mysql_query("insert into freetplclassified_transactions (uid,amount,description,date_submitted) values (".$_SESSION["freetpl_clsplus_userid"].",$buy_now,'Enabled buynow option for classified ''$product_name''','".date("YmdHis",time())."')"); } } $msg="Your classified has been added "; if($approved<>"yes") { $msg.="and sent for Admin approval"; } } else { $msg="Your classified has been added without any listing feature due to low balance."; { $msg.="Classified has been sent for Admin approval"; } } $sql= "INSERT INTO freetplclassified_products (product_name,cid,aucid,location,auction_period,featured,approved,country,product_desc,date_submitted,uid,no_of_views,state,status,winner,bold,highlight,fp_featured,gallery_featured,paypal_id,counter_id,additional_info,buy_price, freetplextra_shipping) VALUES('$product_name','$cid','$aucid','$location','$auction_period','$featured','$approved',$country,'$product_desc','" . date("YmdHis",time()). "'," .$_SESSION["freetpl_clsplus_userid"].",0,'$state','open','0','$bold','$highlight','$fp_featured','$gallery_featured','$paypal_id',$counter_id,'$additional_info',$buy_price, $freetplextra_shipping)"; //echo "$sql<br>"; mysql_query($sql); ////////MAIL TO SaLLER////////////////////// if(mysql_affected_rows() > 0) { $id=mysql_insert_id(); } // This - $freetplrow_con=mysql_fetch_array(mysql_query("select * from freetplclassified_config")); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_config"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $freetplrow_con = mysql_fetch_array($result); $null_char[0]=$freetplrow_con['null_char']; $site_root[0]=$freetplrow_con['site_root']; $freetplreturn_arg=($freetplreturn)?"&id=$id":''; // This - $rs0=mysql_fetch_array(mysql_query("select * from freetplclassified_products where id=$id")); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_products WHERE id=$id"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $rs0 = mysql_fetch_array($result); $product_url="{$site_root[0]}/product_desc.php?id={$rs0['id']}"; $product_url="<a href='$product_url' target='_blank' title='Click to view product'>$product_url</a>"; $login_url="{$site_root[0]}/signinform.php"; $login_url="<a href='$login_url' target='_blank' title='Click to login now'>$login_url</a>"; // This - $rs1=mysql_fetch_array(mysql_query("select * from freetplclassified_members where id={$rs0['uid']})); - // can be broken down into the 3 lines below. $sql = "SELECT * FROM freetplclassified_members WHERE id={$rs0['uid']}"; $result = mysql_query($sql) or die(mysql_error()); //take out or die clause afterwards $rs1 = mysql_fetch_array($result); //Reads email to be sebt $sql = "SELECT * FROM freetplclassified_mails where mailid=$freetplmailid" ; $rs_query=mysql_query($sql); if ( $rs=mysql_fetch_array($rs_query) ) { $from =$rs["fromid"]; // $to = $rs1["email"]; $to=($freetplmailid==5)?$rs1["email"]:$rate["admin_email"]; $subject =$rs["subject"]; $header="From:" . $from . "\r\n" ."Reply-To:". $from ; if($rs["freetpl_html_format"]=="yes") { $header .= "\r\nMIME-Version: 1.0"; $header .= "\r\nContent-type: text/html; charset=iso-8859-1\r\n"; } $body=str_replace("%fname%",$rs1["fname"],str_replace("%lname%",$rs1["lname"],str_replace("%email%",$rs1["email"],str_replace("%username%",$rs1["username"],str_replace("%password%",$null_char[0],str_replace("%loginurl%",$login_url,$rs["mail"])))))) ; $body=str_replace("%productname%",$rs0["product_name"],str_replace("%producturl%",$product_url,str_replace("%noofbids%",$null_char[0],str_replace("%currentbid%",$null_char[0],str_replace("%bidder_username%",$null_char[0],str_replace("%expired_date%",$null_char[0],$body)))))); $body=str_replace("%message_text%",$null_char[0],str_replace("%message_title%",$null_char[0],str_replace("%sender_username%",$null_char[0],str_replace("%message_time%",$null_char[0],str_replace("%message_date%",$null_char[0],$body))))); @mail($to,$subject,$body,$header); // echo "--from:-$from----to:-$to---sub:-$subject----head:-$header----"; // echo "<pre>$body</pre>"; } header("Location: gen_confirm_mem.php?$freetplreturn_arg&errmsg=".urlencode($msg)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-892478 Share on other sites More sharing options...
Maq Posted August 10, 2009 Share Posted August 10, 2009 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 There is no query on line 1, so it's probably referring to the include file (even though that's not on line 1). Is that the whole error message? If not, please post it. Quote Link to comment https://forums.phpfreaks.com/topic/169117-warning-mysql_fetch_array/#findComment-895044 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.