/    Sign up×
Community /Pin to ProfileBookmark

mysql_fetch_assoc question

why am i getting this error with mysql_fetch_assoc? ?

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/mediatec/public_html/jrknowles/dow/assignment1/includes/login.php on line 29

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/mediatec/public_html/jrknowles/dow/assignment1/includes/login.php on line 45

[code=php]
echo “<h1>Current Members</h1>”;
echo “<table>”;
$filter = “user_id”;
$query = “SELECT * FROM assi1”;
/*$query .= “ORDER BY $filter DESC”;*/
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
echo “<tr>”;
echo “<td>” . $row[‘user_id’] . “</td>”;
echo “<td>” . $row[‘title’] . “</td>”;
echo “<td>” . $row[‘first_name’] . “</td>”;
echo “<td>” . $row[‘last_name’] . “</td>”;
echo “<td>” . $row[’email’] . “</td>”;
echo “<td>” . $row[‘house_number’] . “</td>”;
echo “<td>” . $row[‘street’] . “</td>”;
echo “<td>” . $row[‘city’] . “</td>”;
echo “<td>” . $row[‘county’] . “</td>”;
echo “<td>” . $row[‘postcode’] . “</td>”;
echo “<td>” . $row[‘country’] . “</td>”;
echo “</tr>”;
}
mysql_free_result($result);
echo “</table>”;
[/code]

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@bokehFeb 28.2006 — [code=php]$result = mysql_query($query);[/code][/QUOTE]This is happening because the query failed for some reason. Change the above line to the following to display the error.[code=php]$result = mysql_query($query) or die(mysql_error());[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYFeb 28.2006 — It is happening, because as bokeh said, the query failed, and thus the mysql_query() function returned a boolean value of false, and not a handle.
Copy linkTweet thisAlerts:
@knowjauthorMar 05.2006 — ok the reason is its saying theres no table

iv done a table creation script but it doesnt seem to be working

Table creation script:
[code=php]
<?
//connect to the database
require_once "includes/connection.php";
//query to make the table
$query = "CREATE TABLE 'assi1' (
'user_id' tinyint(8) NOT NULL auto_increment,
'title' varchar(150) NOT NULL,
'first_name' varchar(150) NOT NULL,
'last_name' varchar(150) NOT NULL,
'email' varchar(150) NOT NULL,
'house_number' varchar(150) NOT NULL,
'street' varchar(150) NOT NULL,
'city' varchar(50) NOT NULL,
'county' varchar(50) NOT NULL,
'postcode' varchar(7) NOT NULL,
'country' varchar(50) NOT NULL,
PRIMARY KEY (user_id)
)";
echo 'Creating table: 'assi1'....';
//process the query
mysql_db_query($link, $query);
?>[/code]
Copy linkTweet thisAlerts:
@NogDogMar 05.2006 — Is mysql_db_query() a user function you created, or a typo?
Copy linkTweet thisAlerts:
@knowjauthorMar 05.2006 — typo
Copy linkTweet thisAlerts:
@NogDogMar 05.2006 — Assuming it's supposed to be mysql_query(), the arguments are in the wrong order. Also try doing something like the following to get more debug info:
[code=php]
// don't need the 2nd arg to mysql_query unless you have multiple connections
mysql_query($query, $link) or die("Query failed: $query - " . mysql_error());
[/code]
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMar 05.2006 — the mysql_db_query() function does exist, but it is deprecated!
Copy linkTweet thisAlerts:
@chazzyMar 05.2006 — The reason why your table create is getting errors is because of the single quotes '. you need to replace them with back ticks `
×

Success!

Help @knowj 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.13,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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