/    Sign up×
Community /Pin to ProfileBookmark

mysql_fetch_assoc

I have an error using the mysql_fetch_assoc defined function..i used it before in a lot of my scripts..what im i doing wron here?? its get an id value from the previous page..it does pass the $_GET proeperly..urghh lol hehe 😑

[code=php]
if(isset($_GET[‘key’])) {
$id = $_GET[‘key’];

$mysql_server = “***********”;
$mysql_user = “***********”;
$mysql_password = “***********”;
$connect=mysql_connect ($mysql_server, $mysql_user, $mysql_password) or die(“cannot make connection”);
$dbselect=mysql_select_db (“***********”) or die(“cannot select database”);
//sql statments
$result = mysql_query(“SELECT * WHERE ordernum = `$id`;”);

while ($row = mysql_fetch_assoc($result))
{
echo $row[“prodnum”];
}
}
[/code]

I get the following php error:

[I]Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/h/i/s/hispanonatura/html/test/products5/admin/vieworder.php on line 31[/I]

any suggestions are apprecited ?

to post a comment
PHP

14 Comments(s) ↴

Copy linkTweet thisAlerts:
@JonaJul 22.2005 β€”Β [font=Trebuchet MS]Try...[/font]

[code=php]
$result = mysql_query("SELECT * WHERE ordernum = '$id'");
[/code]
Copy linkTweet thisAlerts:
@vicpal25authorJul 22.2005 β€”Β nahh same thing ? ..


current code:
[code=php]
$result = mysql_query("SELECT * WHERE ordernum = '$id';");
//fetch results into variables $count (counts records from database) and $row will fetch results into an array

while ($row = mysql_fetch_assoc($result))

{
echo $row["prodnum"];
}
}
[/code]
Copy linkTweet thisAlerts:
@BeachSideJul 22.2005 β€”Β nahh same thing ? ..


current code:
[code=php]
$result = mysql_query("SELECT * WHERE ordernum = '$id';");
//fetch results into variables $count (counts records from database) and $row will fetch results into an array

while ($row = mysql_fetch_assoc($result))

{
echo $row["prodnum"];
}
}
[/code]
[/QUOTE]

You need to remove that first semi-colon after '$id'

so it needs to be as Jona said
[code=php]
$result = mysql_query("SELECT * WHERE ordernum = '$id'");
[/code]
Copy linkTweet thisAlerts:
@vicpal25authorJul 22.2005 β€”Β nope..do you think its the query? i tried hard coding the value of the $_GET value and still..no cigar...
Copy linkTweet thisAlerts:
@BeachSideJul 22.2005 β€”Β Only if you don't have a field with the name ordernum and there is only one table
Copy linkTweet thisAlerts:
@vicpal25authorJul 22.2005 β€”Β yup its there in that same table....hummm..
Copy linkTweet thisAlerts:
@BeachSideJul 22.2005 β€”Β try SELECT * FROM tablename and see what you get
Copy linkTweet thisAlerts:
@NogDogJul 22.2005 β€”Β The error message definitely indicates that the query failed (thus the "supplied argument is not a valid MySQL result resource"). Try changing your mysql_query line to something like this so you can at least see what the mysql error message is:
[code=php]
$query = "SELECT * WHERE ordernum = '$id'";
$result = mysql_query($query) or die("Query failed: " . mysql_error() . " - " . $query);
[/code]

PS: if ordernum is a numeric column, you might not want the quotes around $id (not positive how MySQL feels about automatically casting strings to numbers).
Copy linkTweet thisAlerts:
@vicpal25authorJul 22.2005 β€”Β HEYY I KNOW WHAT IT IS...YOU GUYS SEE THE SELECT STATEMENT??? THERE IS NO FROM!!!!!!!!!!!! SELECT * FROOOOOOOOOOOMMMMM URGHHH HEHE. thanks you guys..
Copy linkTweet thisAlerts:
@NogDogJul 22.2005 β€”Β Doh!

?
Copy linkTweet thisAlerts:
@vicpal25authorJul 22.2005 β€”Β ?~
Copy linkTweet thisAlerts:
@BeachSideJul 22.2005 β€”Β HEYY I KNOW WHAT IT IS...YOU GUYS SEE THE SELECT STATEMENT??? THERE IS NO FROM!!!!!!!!!!!! SELECT * FROOOOOOOOOOOMMMMM URGHHH HEHE. thanks you guys..[/QUOTE]

I shall point you to post #8 ?
[B]try SELECT * FROM tablename and see what you get[/B][/QUOTE]
Copy linkTweet thisAlerts:
@NogDogJul 22.2005 β€”Β And if you get in the habit of assuming there might be an error and reporting it as in my Post #9, you'll find these things right away. ?
Copy linkTweet thisAlerts:
@BeachSideJul 23.2005 β€”Β And if you get in the habit of assuming there might be an error and reporting it as in my Post #9, you'll find these things right away. ?[/QUOTE]
I am with you 100%!

Always always always and I cannot stress this enough [B][U][COLOR=Red]always[/COLOR][/U][/B] assume there is an error :p
Γ—

Success!

Help @vicpal25 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 5.3,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...