ballhogjoni Posted January 26, 2007 Share Posted January 26, 2007 can someone tell me why my api call is not working? I get this error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in .../xxxxxx.php on line 14[code]<?php $username="xxxxx";$password="xxxxx";$database="xxxxx";mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$result = mysql_query("SELECT first, last, email, address, city, state, zipcode, phone FROM xxxxx ORDER BY id DESC");$result2 = mysql_query("SELECT expyear, expmonth, ccnumber FROM xxxxx ORDER BY id DESC");$result1 = mysql_fetch_array($result);$result3 = mysql_fetch_array($result2);mysql_close();$phone = rawurlencode($result1['phone']);$first = rawurlencode($result1['first']);$last = rawurlencode($result1['last']);$email = $result1['email'];$address = rawurlencode($result1['address']);$city = rawurlencode($result1['city']);$state = $result1['state'];$zipcode = rawurlencode($result1['zipcode']);$ccnumber = rawurlencode($result3['ccnumber']);$expyear = $result3['expyear'];$expmonth = $result3['expmonth'];$username = 'xxxxx'; $password = 'xxxxx'; $command = "user.configure";$user_id = "NEW";$url = "https://www.xxxxx.com/auto/api.php?partner_login=$username&partner_password=$password&test=TRUE&command=$command&user_id=$user_id&service=\"code=DS,frequency=M,action=add,renewal_billed_to=U,trial=14\"&output=php&phone=$phone&first_name=$first&last_name=$last&bill_address1=$address&bill_address2=&bill_city=$city&bill_state=$state&bill_postal=$zipcode&bill_country=US&username=foousername&password=foopassword&cc_num=$ccnumber&cc_exp=$expyear-$expmonth&email=$email";$ch = curl_init();curl_setopt( $ch , CURLOPT_URL , $url); //the url curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s curl_setopt($ch, CURLOPT_POST, 1); // set POST method$ret = curl_exec($ch); curl_close($ch); ?>[/code] Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/ Share on other sites More sharing options...
Tandem Posted January 26, 2007 Share Posted January 26, 2007 Add a or die(mysql_error()) to the end of the query in question, i.e.$result2 = mysql_query("SELECT expyear, expmonth, ccnumber FROM xxxxx ORDER BY id DESC") or die(mysql_error());Maybe that will tell you the problem, as i can't see any obvious errors. Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169408 Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Author Share Posted January 26, 2007 no that dint tell me anything different. Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169413 Share on other sites More sharing options...
trq Posted January 26, 2007 Share Posted January 26, 2007 Never use the result from a query untill you check your query was actually successful. Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169430 Share on other sites More sharing options...
ballhogjoni Posted January 26, 2007 Author Share Posted January 26, 2007 what do you mean? Its funny you say that because it was working about two weeks ago and then I just started testing it again. Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169431 Share on other sites More sharing options...
deadonarrival Posted January 26, 2007 Share Posted January 26, 2007 Make sure there's something in the table you're trying to select from! Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169434 Share on other sites More sharing options...
Tandem Posted January 26, 2007 Share Posted January 26, 2007 One method of checking if the query was successful:[code]$result2 = mysql_query("SELECT expyear, expmonth, ccnumber FROM xxxxx ORDER BY id DESC") or die(mysql_error());$result2_num = mysql_num_rows($result2);if ($result2_num > 0) {$result3 = mysql_fetch_array($result2);}if ($result2_num < 1) {echo "Unsuccessful";}[/code] Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169435 Share on other sites More sharing options...
trq Posted January 26, 2007 Share Posted January 26, 2007 That will still throw errors if the query fails. The safest way to execute a query would be....[code]<?php $sql = "SELECT * FROM foo"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // it is now safe to use your result in here. } else { echo "No records found"; } } else { echo "Query failed ".mysql_error()."<br />$sql"; }?>[/code] Link to comment https://forums.phpfreaks.com/topic/35747-warning-mysql_fetch_array-supplied-argument/#findComment-169436 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.